| Store | Cart

Re: command line argument

From: Dirk Bremer \(NISC\) <dirk...@nisc.cc>
Wed, 29 Jan 2003 08:46:38 -0600
----- 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

Recent Messages in this Thread
Andrew Mansfield Jan 29, 2003 02:29 pm
Richard Morse Jan 29, 2003 02:44 pm
Dirk Bremer \(NISC\) Jan 29, 2003 02:46 pm
Carl Jolley Jan 30, 2003 08:00 pm
Messages in this thread