Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: using $ARGV without arguments

by Bilbo (Pilgrim)
on Jun 24, 2003 at 14:07 UTC ( [id://268512]=note: print w/replies, xml ) Need Help??


in reply to using $ARGV without arguments

Well, if you don't put any arguments in then $ARGV[0] is undefined. What do you want to do if no arguments are given? Do you want it to cause an error:

unless (@ARGV == 1) { die "You must specify one argument\n"; }

Or do you want to set a default value?

my $argument = $ARGV[0] || 'default' ; # Put your default # value here if ($argument eq 'TEST') {....

Or do you just want it to ignore the argument?

if (defined $ARGV[0] && $ARGV[0] eq 'TEST') {...

Replies are listed 'Best First'.
Amateur Perl Hacker
by Arbogast (Monk) on Jun 24, 2003 at 15:26 UTC
    Question on acceptable practice.

    Subject, warning on Use of uninitialized value in string eq at ...

    When this happens, I go back and check my code to make sure it is OK the value is sometimes unitialized. If it OK, I move on and dont worry about it.

    Is this a bad habit???
      Yes. Lots of Famous Really Good Programmers (tm) will tell you to always initialize vars---but since I'm not one of them, I'll tell you to at least try and make it a habit since it will save you grief later on. My rule is that if there is a chance that I'll check the value before I stuff something in it, I'll usually set it to a known value...

      --hsm

      "Never try to teach a pig to sing...it wastes your time and it annoys the pig."

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-04-23 11:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found