in reply to PERL - newbie: first time working with GetOptions error given when running script

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} ] );

Replies are listed 'Best First'.
Re^2: PERL - newbie: first time working with GetOptions error given when running script
by lshokri02 (Novice) on Oct 06, 2014 at 13:03 UTC
    Ohh, the three number values have nothing to do with the options, I'd want those either parameters to go into ( $beginAddrHex, $endAddrHex, $numberOfSims ) either ways. I thought the GetOptions would just see if any or all of the three options are enabled/disabled. Then after it would take the arguments, so even if "err_dup" is disabled I'd get the values.