LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   perl arguments (https://www.linuxquestions.org/questions/programming-9/perl-arguments-295474/)

zaken 02-27-2005 09:48 AM

perl arguments
 
OK I'm a newbie at perl. whats wrong with the perl below??? I keep getting errors

Global symbol "$hostfile" requires explicit package name at ./multi-rtr-cmd.pl line 14.
Global symbol "$outputfile" requires explicit package name at ./multi-rtr-cmd.pl line 16.
Global symbol "$command1" requires explicit package name at ./multi-rtr-cmd.pl line 18.
Global symbol "$command2" requires explicit package name at ./multi-rtr-cmd.pl line 20.
Global symbol "$outputfile" requires explicit package name at ./multi-rtr-cmd.pl line 31.



These are being generated by the piece of script below.
I've tried all sorts of different quotes and reading various bits.
Please help me on my learning path.

# Read in the arguments into script variables

if(!"@ARGV"){&Usage};

if($ARGV[0] eq "-i") {$hostfile = "$ARGV[1]"};

if($ARGV[2] eq "-o") {$outputfile = "$ARGV[3]"};

if($ARGV[4] eq "-c1") {$command1 = "$ARGV[5]"};

if($ARGV[6] eq "-c2") {$command2 = "$ARGV[7]"};

TIA,
Neil.

david_ross 02-27-2005 11:19 AM

It looks like you have "use strict;" You will need to declare the variables with:
my $varname;


All times are GMT -5. The time now is 04:44 PM.