You're use'ing Getopt but you aren't actually using it.
The following code has absolutely no place in your program if you're using Getopt::Long:
$beginAddrHex = $ARGV[0]; $endAddrHex = $ARGV[1]; $numberOfSims = $ARGV[2];
You should be letting GetOptions do the work of getting the options. That's its reason for being. Your line should probably look more like this.:
GetOptions( \%options, qw[ help+ delete+ err_dup=s{3} ] );
This also means your %options hash should look something like this (if you believe in pre-populating it).:
my %options = ( 'help' => 0, 'delete' => 0, 'err_dups' => [], );
And then your if branch for err_dup would be more like this.:
if ( $options{ 'err_dup' } ){ print "err_dup is called\n"; my ( $beginAddrHex, $endAddrHex, $numberOfSims ) = @{ $options +{ 'err_dup' } }; # or just pass the option straight to the sub you're + about to call } else { print "err_dup NOT called\n"; }
Why you'd use GetOptions to make all the options numeric flags then try to pick apart @ARGV (with the wrong indexes, BTW) is beyond me. Just follow the docs and use string options and repetition specifiers (called a "repeat specifier" in the docs). You can also specify an array type if you're not sure how many you'll need.
Oh, and since you're using hex you could enforce option type checking if you're willing to enter your hex values as 0xf68 and 0xF100 and such.:
GetOptions( \%options, qw[ help+ delete+ err_dup=o{3} ] );
In reply to Re: PERL - newbie: first time working with GetOptions error given when running script
by mr_mischief
in thread PERL - newbie: first time working with GetOptions error given when running script
by lshokri02
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |