in reply to getopt::std to pass arguments to command line help

I recommend Getopt::Long, storing all options in a hash:
use warnings; use strict; use Getopt::Long qw(GetOptions); my %opt = (logdir => 'foo'); GetOptions(\%opt, qw(logdir=s)) or die; print "logdir=$opt{logdir}\n"; __END__ Run it like: myprog.pl -logdir bar Output: logdir=bar

Replies are listed 'Best First'.
Re^2: getopt::std to pass arguments to command line help
by Discipulus (Canon) on Jan 21, 2015 at 08:19 UTC
    hextor look at that good example by toolic and pay attention to the GetOptions ... or die; part.
    This is very important because you dont want your program to execute with wrong or not accepted args.
    Personally i ended using everytime yet another idiom, even more cautious:
    use Getopt::Long; use Pod::Usage; # if you have documentation embedded is better unless (GetOptions( "option=s" => \$option ... )) { pod2usage(-verbose => 1,-exitval => 'NOEXIT'); # automatic u +sage printing (if you have an usage section in POD) &wait_for_input; # if the prog + was opend in a 'double click' fashion there is no time # to review e +rrors, if so you can just use something like: # sub wait_fo +r_input{ # print "\n +\nPress Return when ready\n"; # while (<S +TDIN>){last if $_ } # } exit; # now you can + exit or die with yet another error string }

    HtH
    L*
    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Re^2: getopt::std to pass arguments to command line help
by hextor (Initiate) on Jan 20, 2015 at 21:10 UTC
    Thank you. I will look into getopt::long.