You don't want a switch statement. What switch does is take a variable and do different stuff based on the value held within that variable. You need to set $_ to something (say within a loop) otherwise the results will be unexpected. You have several key value pairs in your %opt hash and you just want to do stuff based on what they hold. I expect this will do what you want. Pick whichever variations of syntax/function that work best for you.

defined $opt{1} and read_structure_type1($opt{1}); defined $opt{2} and read_structure_type2($opt{2}); read_structure_type3($opt{3}) if defined $opt{3}; defined $opt{f} and do{ $fldname = $opt{f} }; $length = $opt{l} if defined $opt{l}; $location = defined $opt{L} ? $opt{L} : 'default'; $infile = $opt{i} || 'default'; $dirname = $opt{d} || '/dev/null'; do {usage(); exit; } if defined $opt{h} or not %opt;

In reply to Re: Need help: Getopt by tachyon-II
in thread Need help: Getopt by bh_perl

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.