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

Command Line Options

by bitswitch (Scribe)
on May 09, 2001 at 19:45 UTC ( #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 (Chaplain) 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).

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: -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?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://79126]
Approved by root
and the monks are mute...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2018-05-23 17:40 GMT
Find Nodes?
    Voting Booth?