Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

New Perl Question

Options
  • 19-01-2009 5:46pm
    #1
    Registered Users Posts: 465 ✭✭


    Hi

    I am trying to open a command prompt inside my perl script and run a command. It is not recognising the two variables as i think the syntax i am using is wrong. Can anybody shed any light on this? Thanks.


    $printLocn = "\\\\server\\printername" ;

    my $cmd = 'perl -pi -e -d copy $file $printLocn'; (think this is wrong?)
    runCMDCommand();

    sub runCMDCommand {

    my @output = `$cmd`;
    print("CMD:$cmd\n");
    }


Comments

  • Registered Users Posts: 26,579 ✭✭✭✭Creamy Goodness


    You need to use "" double quotes so that the variables on line 3 get substituted the actual variable value.

    Using '' single quotes causes perl to see $var as just that $var

    Also your sub routine does not know of the variable $cmd as it is not passed to the routine although perl may let you away with this if you omit the use strict pragma


  • Registered Users Posts: 817 ✭✭✭Burial


    You need to use " instead of ' when using variables. Your program just reads it as what its written as.

    So lets say, $Variable = 5;

    1.) print("$Variable");

    2.) print('$Variable');

    Output:

    1.) 5

    2.) $Variable

    I hope that helps.


  • Registered Users Posts: 465 ✭✭coco06


    Hey

    Once i looked at it with a clear head again this morning i realized i can just use the copy function in the script itself and dont need to open command prompt window...

    Thanks


  • Registered Users Posts: 6,509 ✭✭✭daymobrew


    coco06 wrote: »
    Once i looked at it with a clear head again this morning i realized i can just use the copy function in the script itself and dont need to open command prompt window...
    Do you mean use the File::Copy module?

    I always encourage the use of native functions over command prompt and other external tools. Native functions will be more portable.


  • Registered Users Posts: 465 ✭✭coco06


    daymobrew wrote: »
    Do you mean use the File::Copy module?

    I always encourage the use of native functions over command prompt and other external tools. Native functions will be more portable.

    Yes the file::copy module. Just took me a little time to get the brain working..


  • Advertisement
Advertisement