Hello,

My question might be a bit stupid but it would be nice if i could get it to work.

I have a command line option, say -x. In the GetOptions() function i have declared it as GetOptions('x:s'=>\$x);

Incase the -x option is given with a string, $x gets that value.

Incase the -x option is given with no string , $x becomes 0.

Is there anyway for me to acheive both, handle the case where if some value is passed $x contains that string and if no value is passed, $x remains true. ie not 0.

for eg

perl someprogram.pl -x "hello" // $x becomes "hello"
perl someprogram.pl -x // $x becomes 0, but i want it to be set to true, since the option wa +s entered on command line.

It is a stupid question, but i want to be able to use the same variable, to do differnt things.

Is this even possible? :O

Thanks!

20100721 Janitored by Corion: Added formatting, code tags, as per Writeup Formatting Tips


In reply to Wisdom on the Getopt::Long module by abhijithtk

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.