in reply to Getopt configuration
Note - the output is coming from the called sub's.#Test getopt use strict; use warnings; use Getopt::Long; my %opt; # Main options my %oa=( # Option attributes.. this=> { type=>'i', ifset=>sub{print qq(this is set\n)} }, that=> { type=>'s' }, other=> { type=>'i' , ifset=>sub{print qq(Other is set=) .shift().q +q(\n)} } ); my @GetOpt_str; push @GetOpt_str ,"$_=$oa{$_}{type}" for keys %oa; #print "\tOptStr=@GetOpt_str;\n"; GetOptions (\%opt , @GetOpt_str); # Call all procs specified .. exists $oa{$_}{ifset} and $oa{$_}{ifset}->($opt{$_}) for keys %opt; --Run with options and output--- >perl test-getopt.pl -other=44 -this=9999 Other is set=44 this is set
Earth first! (We'll rob the other planets later)
|
|---|