Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

How to find what options are used for Getopt::Long

by doubledecker (Scribe)
on Aug 03, 2012 at 08:57 UTC ( #985194=perlquestion: print w/replies, xml ) Need Help??
doubledecker has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks

Is there any way that we can find out from my current perl script of which options I've passed for running this script. I'm using Getopt::Long inside my perl script. any hash which will tell me what options i've used to invoke the script as I've bunch of options used

  • Comment on How to find what options are used for Getopt::Long

Replies are listed 'Best First'.
Re: How to find what options are used for Getopt::Long
by toolic (Bishop) on Aug 03, 2012 at 12:17 UTC
    Another way is to store all your opt in a hash instead of individual scalars:
    use warnings; use strict; use Getopt::Long; use Data::Dumper; $Data::Dumper::Sortkeys=1; my %opt; GetOptions(\%opt, qw( help cfg=s verbose silent dir=s )) or die "Mandatory options not supplied\n"; print Dumper(\%opt); __END__ script.pl -h -v $VAR1 = { 'help' => 1, 'verbose' => 1 };

      Works for me

Re: How to find what options are used for Getopt::Long
by Anonymous Monk on Aug 03, 2012 at 09:08 UTC
Re: How to find what options are used for Getopt::Long
by cztmonk (Monk) on Aug 03, 2012 at 09:26 UTC

    Maybe you should post some code to make your question more clear...

      here is my code

      #!/usr/bin/perl use strict; use Getopt::Long; $Getopt::Long::autoabbrev = 1; $Getopt::Long::ignorecase = 0; my ($opt_help, $opt_cfg, $opt_verbose, $opt_silent, $opt_dir); GetOptions( "help" => \$opt_help, "cfg=s" => \$opt_cfg, "verbose" => \$opt_verbose, "silent" => \$opt_silent, "dir=s" => \$opt_dir, ) or die "Mandatory options not supplied\n"; # How to find out which option is passed via Getopt. # I can rely on the variables for their definedness, but options might + increase and # considerably. Is there any short way that I can find where all the o +ptions are stored # say in a hash.
        #!/usr/bin/perl -- my @argv = @ARGV; ... your code here ... use Data::Dump; dd { before => \@argv, after => \@ARGV };

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://985194]
Approved by marto
help
Chatterbox?
and !@monks...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2016-12-09 00:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (148 votes). Check out past polls.