Getopt::Long doesn't work exactly like Getopt::Std, like I showed, so use
GetOption( 'd=s' => $opt_d, # d 'h=s' => $opt_h, # h 'l=s' => $opt_l, # l 'L=s' => $opt_L, # L 'i=s' => $opt_i, # i 'o!' => $opt_o, # o: 'P!' => $opt_P, # P: 'p=s' => $opt_p, # p 'q=s' => $opt_q, # q 'r=s' => $opt_r, # r 'v!' => $opt_v, # v: 'c=s' => $opt_c, # c )
or
GetOption( %h,#values in %h 'd=s', # d 'h=s', # h 'l=s', # l 'L=s', # L 'i=s', # i 'o!', # o: 'P!', # P: 'p=s', # p 'q=s', # q 'r=s', # r 'v!', # v: 'c=s', # c )
generated with
#!/usr/bin/perl -- use strict; use warnings; Main( @ARGV ); exit( 0 ); sub Main { StdToLong('dhlLio:P:pqrv:c'); } BEGIN { my %Flags = ( #~ ':' => '', # boolean, default ':' => '!', # boolean, explicit, negatable '' => '=s', ); sub StdToLong { StdToLong1(@_); StdToLong2(@_); } sub StdToLong1 { print "GetOption(\n"; while( $_[0] =~ m/(\w)(\W)?/g ){ no warnings 'uninitialized'; print qq[ '$1$Flags{$2}' => \$opt_$1, # $1$2 \n]; } print "\)\n"; } sub StdToLong2 { print "GetOption( \%h,#values in %h\n"; while( $_[0] =~ m/(\w)(\W)?/g ){ no warnings 'uninitialized'; print qq[ '$1$Flags{$2}', # $1$2 \n]; } print "\)\n"; } } __END__

In reply to Re^3: getopts and -? by Anonymous Monk
in thread getopts and -? by viffer

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.