Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Command Line Options

by bitswitch (Scribe)
on May 09, 2001 at 19:45 UTC ( [id://79126]=perlquestion: print w/replies, xml ) Need Help??

bitswitch has asked for the wisdom of the Perl Monks concerning the following question:

I have tried various ways of doing command line options, such as sub expressions and using the Getopt modules. However, I'd like to know how my fellow monks go about doing this.
Thanks for any feedback.

Edit: chipmunk 2001-05-09

Replies are listed 'Best First'.
Re: Command Line Options
by isotope (Deacon) on May 09, 2001 at 20:00 UTC
    If I'm going to bother with command line options, I almost always use Getopt::Long. It's big, but it works quite well (I really like that it removes the options from @ARGV so I can use <> later, and that it can do some validation of the options, etc).

    --isotope
    http://www.skylab.org/~isotope/
Re: Command Line Options
by japhy (Canon) on May 09, 2001 at 22:44 UTC
    I like -s. It lets me do things like:
    #!/usr/bin/perl -ws use strict; our ($name, $age, $sex); # ...
    and run the code like: prog.pl -name="Jeff Pinyan" -sex=male -age=19. I even got 10 characters or so added to Perl's source code to allow double-hyphens (if you're into that sort of thing).

    japhy -- Perl and Regex Hacker
Re: Command Line Options
by frag (Hermit) on May 09, 2001 at 23:39 UTC
    I like Getopt::Mixed, which lets you use either "-abc=foo", "--alpha --beta --cletus=foo", or, "--alpha -bc=foo".
    ### EZ way: use Getopt::Mixed; Getopt::Mixed::getOptions qw( help h>help file f>file list=i l>list ); print "$opt_help, $opt_file, $opt_list"; ### 'Harder' way (more flexible, but you have more to write): use Getopt::Mixed "nextOption"; Getopt::Mixed::init qw( help h>help file f>file id=i i>id ); my ($opt_id, $opt_file, $opt_help); while (($option, $value, $pretty) = nextOption()) { if ($option eq 'id') { $opt_id = $value; } elsif ($option eq 'help') { # etc. } }

    -- Frag.

Re: Command Line Options
by robsv (Curate) on May 09, 2001 at 21:10 UTC
    I'm with isotope. I find that command line parms with longer names are easier to remember. I generally use Getopt::Long something like this:
    GetOptions("file=s" => \my $input_file, "verbose" => \$VERBOSE, "help" => \my $HELP) or die "Insert usage message here";
    Getopt::Long is also flexible enough to allow bundling of single-character options like Getopt::Std.

    - robsv

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-24 21:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found