pass_through configuration option and &GetOptionsFromArray has a solution -- complete with option requirement type checking -- for you ...

cat p.pl perl p.pl -h -p 1 ; \ perl p.pl -p q -h ; \ perl p.pl -p -h ; \ perl p.pl -p q ; \ perl p.pl -p ; \ perl p.pl -p 3 use strict; use warnings; # May or may not work wit previous version(s). use Getopt::Long 2.38; my ( $h ); Getopt::Long::Configure( 'pass_through' ); GetOptions( 'help' => \$h ); die "HELP" if $h; my ( $p ); Getopt::Long::Configure( 'nopass_through' ); Getopt::Long::GetOptionsFromArray ( \@ARGV , 'p=i' => \$p ) or die; printf "p: %s\n" , defined $p ? $p : 'undef'; __END__ HELP at p.pl line 10. HELP at p.pl line 10. HELP at p.pl line 10. Value "q" invalid for option p (number expected) Died at p.pl line 14. Option p requires an argument Died at p.pl line 14. p: 3

In reply to Re: Help required on Getopt::Long by Anonymous Monk
in thread Help required on Getopt::Long by ghosh123

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.