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 5

this 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!


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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.