toolic, thank you for taking the time on this.

I did cut and paste your code and uncommented the usage of Data Dumper to see what was happening.

Using -t, I get

./714799.pl -t opt $VAR1 = { 't' => undef }; neither -t or -s used

with similar results for a singular -s.

Observe the test to see if either option had been specified fails.

Using both -s and -t I get

./714799.pl -s -t opt $VAR1 = { 's' => '-t' }; either -t or -s used

Using -a -b gives

./714799.pl -a -b opt $VAR1 = { 'a' => 1, 'b' => 1 }; neither -t or -s used

and singletons of either give one hash element with the value one.

So I still feel there is something strange about at least s and t as options for getopt.

I read the documentation and saw that getopt and getopts appear to behave differently.

It is mea culpa because the documentation clearly states getopt expects each switch to have an argument. Therefore -s -t should interpret -t as the argument to the -s switch (and vice versa).

Except this doesn't appear to hold if one uses -a -b. Here the default value of 1 is used for both.

I may try checking the rest of the alphabet on this one

The end result is the getopts function behaves the way I originally expected getopt to behave

Thank you once again for taking the time on this

Update

./714799.pl -a -b -c -d -e -f -g -h -i -j -k -l -m -n -o -p -q -r -s - +t -u -v -w -x -y -z opt $VAR1 = { 'w' => 1, 'r' => 1, 'a' => 1, 'x' => 1, 'd' => 1, 'j' => 1, 'y' => 1, 'u' => 1, 'k' => 1, 'h' => 1, 'g' => 1, 'f' => 1, 'i' => 1, 'e' => 1, 'n' => 1, 'v' => 1, 'm' => 1, 's' => '-t', 'l' => 1, 'c' => 1, 'p' => 1, 'q' => 1, 'b' => 1, 'z' => 1, 'o' => 1 }; either -t or -s used

and

./714799.pl -a -b -c -d -e -f -g -h -i -j -k -l -m -n -o -p -q -r -s - +u -t -v -w -x -y -z opt $VAR1 = { 'w' => 1, 'r' => 1, 'a' => 1, 'x' => 1, 'd' => 1, 'j' => 1, 'y' => 1, 'k' => 1, 'h' => 1, 'g' => 1, 'f' => 1, 't' => '-v', 'i' => 1, 'e' => 1, 'n' => 1, 'm' => 1, 's' => '-u', 'l' => 1, 'c' => 1, 'p' => 1, 'q' => 1, 'b' => 1, 'z' => 1, 'o' => 1 }; either -t or -s used

-s and -t appear to be hungry in getopt


In reply to Re^4: Detecting an undefined hash key by LesleyB
in thread Detecting an undefined hash key by LesleyB

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.