Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: uninitialized variable

by arturo (Vicar)
on Feb 28, 2001 at 04:04 UTC ( [id://61240]=note: print w/replies, xml ) Need Help??


in reply to uninitialized variable

$location = shift(@ARGV); will set $location to undef if no arguments have been passed to the script (@ARGV refers only to the command line, as bbfu points out). That's why you're getting the warning.

For cases like these, you can either do:

my $location = shift @ARGV or die "usage: $0 [filename]\n";

or, if you want a default,

my $location = shift || 'default value';

Minor amplification shift called without an explicit argument will return the next element of @ARGV if it is called outside a subroutine, and returns the next element of @_ if called within a subroutine.

HTH

Philosophy can be made out of anything. Or less -- Jerry A. Fodor

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://61240]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (6)
As of 2024-04-20 00:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found