lshokri02 has asked for the wisdom of the Perl Monks concerning the following question:
I'm new with Perl, first time trying to use command line arguments and options. I want to provide the user with the options if you say "--help" : the "usage" comes up (doesn't run script) "--delete" : delete old files "--error" : print errors in log file then it will have 3 arguments so the command line would look like this:
learning_perl/script > program.pl --help --delete --err_dup F68 F100 5this is my code for getting the command line but when I run this, I get an error and I know it has to do with the %options hash, but I'm not quite sure how to fix it
sub getCmndArg { # my $num_args = $#ARGV + 1; # if ($num_args != 3) { # print "\nUsage: csv_ext_utl -d begin_addr end_addr numberOfSi +ms\n"; # exit; # } my %options=(); GetOptions(\%options, qw[ help dfiles err_dup ]); if ($options{"help"}){ print "help is called - Help Panel:\n"; } else { print "help is NOT called\n"; } if ($options{"dfiles"}){ print "dfiles is called - deleting old simulation files\n"; my $unlinked = unlink glob {"address_register_sweep_*.sv"}; } else { print "dfiles NOT called\n"; } if ($options{"err_dup"}){ print "err_dup is called\n"; } else { print "err_dup NOT called\n"; } #$deleteFile = $ARGV[0]; $beginAddrHex = $ARGV[0]; $endAddrHex = $ARGV[1]; $numberOfSims = $ARGV[2]; }
Error I receive:
help is called - Help Panel: dfiles is called - deleting old simulation files Odd number of elements in anonymous hash at ./csv_ext_utl line 90 (#1) (W misc) You specified an odd number of elements to initialize a h +ash, which is odd, because hashes come in key/value pairs. err_dup NOT called
If anyone can chime in, I'd appreciate it! Thank you!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: PERL - newbie: first time working with GetOptions error given when running script
by Your Mother (Archbishop) on Oct 03, 2014 at 16:51 UTC | |
|
Re: PERL - newbie: first time working with GetOptions error given when running script
by toolic (Bishop) on Oct 03, 2014 at 16:14 UTC | |
|
Re: PERL - newbie: first time working with GetOptions error given when running script
by mr_mischief (Monsignor) on Oct 03, 2014 at 19:40 UTC | |
by lshokri02 (Novice) on Oct 06, 2014 at 13:03 UTC | |
by mr_mischief (Monsignor) on Oct 06, 2014 at 18:25 UTC | |
|
Re: PERL - newbie: first time working with GetOptions error given when running script
by RTBailey (Novice) on Oct 04, 2014 at 15:59 UTC |