----- Original Message -----
From: "Andrew Mansfield" <Andr...@ki.com>
To: <perl...@listserv.activestate.com>
Sent: Wednesday, January 29, 2003 08:29
Subject: command line argument
> I'm stuck with what is probably a trivial task. I want to see if there's a> command line argument and if so assign it to a variable.> e.g.:>> if ( $ARGV[0] ) {> print "$ARGV[0]\n";> my $date = "$ARGV[0]";> } else {> my $date = "1/15/2003";> }>> The problem is that it doesn't set the $date variable properly and it is
undefined after this test and I get this message
>> Global symbol "$date" requires explicit package name at noname.pl line 16.
Which I believe means its undefined..
>> If I put:> if ( $ARGV[0] ) {> print "$ARGV[0]\n";> my $date = "$ARGV[0]";> print "$date\n";> } else {> (etc.)>> it prints $date..>> Any idea what's going on or any better suggestions on handling this?>
Andrew,
One suggestion that I would make is to move the declaration of the $date
variable out of the scope of the if block:
my $date;
if ( $ARGV[0] ) {print "$ARGV[0]\n";$date = "$ARGV[0]"}
else {$date = "1/15/2003"}
print("$date\n");
Dirk Bremer - Systems Programmer II - ESS/AMS - NISC St. Peters
USA Central Time Zone
636-922-9158 ext. 8652 fax 636-447-4471
dirk...@nisc.cc
www.nisc.cc