Hi Experts,

I am running a perl script which uses GetOpt::Long

giveinfo.pl -name mike -long

where, -name option ("name=s") needs a mandatory string argument

-long is optional flag if set, will provide more details of the user named mike

If i miss the user name while running giveinfo.pl as below then it does not error out -

giveinfo.pl -name -long

In this case, its treating -long as user name and DOES NOT error out. I want that in above case it should error out and say "Option name requires an argument".

FYI. in the below scenario it error out as expected if i use -name at the end of command line -

giveinfo.pl -long -name Option name requires an argument

Can someone please help how can i error out correctly in the below scenerio which is missing name mike -

giveinfo.pl -name -long

I don't want to use "=" as -

giveinfo.pl -name= -long

Thanks and Regards,

Harry

In reply to getopt::long treating option as an argument by harpreetsammi

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.