Thanks for pointing this out! Much of my code uses =s, and I now realize I have bugs. However, upon closer inspection of Getopt::Long, it is documented:
= type [ desttype ] [ repeat ] The option requires an argument of the given type. Supporte +d types are: s String. An arbitrary sequence of characters. It is vali +d for the argument to start with "-" or "--".

Note that it is much less likely (or impossible?) to happen with =i or =f.

For those who store options in a hash, Athanasius' handler approach doesn't apply directly. Here is an equivalent:

use warnings; use strict; use Getopt::Long qw(GetOptions); my %opt; GetOptions(\%opt, qw(name=s long)) or die; if ( (exists $opt{name}) and ($opt{name} =~ /^-/) ) { die "Option name requires an argument\n"; }

or, more generally...

my %opt; my @string_opts = qw(name foo|goo bar); GetOptions(\%opt, qw(help long), map { "$_=s" } @string_opts) or die; for my $oname (@string_opts) { $oname = (split /\|/, $oname)[0]; # handle alternate names if ( (exists $opt{$oname}) and ($opt{$oname} =~ /^-/) ) { die "Option $oname requires an argument\n"; } }

In reply to Re: getopt::long treating option as an argument by toolic
in thread 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.