Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Reading command line flags into variables...?

by Adam (Vicar)
on Feb 01, 2001 at 02:28 UTC ( [id://55642]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Reading command line flags into variables...?

While those modules do what you want, there is a learning curve involved, and they can some times be over kill. If all you need is to say, get the name a user then:
die "usage: script.pl firstName lastName\n" unless 2 == @ARGV; my ( $firstName, $lastName ) = @ARGV;
Of course, if you want a fancier level of flag passing, such as optional parameters, then I recommend using one of the previously mentioned modules. I have rolled my own command line parser, and while it was fun, it was also a serious chunk of code. Don't go down that route.

Replies are listed 'Best First'.
(Coyote) Re: Re: Reading command line flags into variables...?
by Coyote (Deacon) on Feb 01, 2001 at 02:52 UTC
    In the example above, $firstName == '-n' and $lastName == 'Bob'. The command line flags are elements in @ARGV. Getopt::Std takes care of this for you. Also, if you are parsing the command line options by hand, you have to be aware of the order which the arguments were passed to the script.

    Update: I didn't read Adam's post closely enough to notice that he was not using command line flags. My apologies.

    ----
    Coyote

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://55642]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.