hi.. Below is my program but its look the "switch" function did not go to the next option when i run it. Could somebody help me How could i captured all my getopt option from the command line ?
my $opt = 'ah1:2:3:f:l:L:i:d:'; my ($isascii, $fmtfile, $fldname, $length, $location, $infile, $dirnam +e); getopts ("$opt", \%opt); switch ($_) { case {$opt{1}} { read_structure_type1($opt{1}); next; } case {$opt{2}} { read_structure_type2($opt{2}); next; } case {$opt{3}} { read_structure_type3($opt{3}); next; } case {$opt{f}} { $fldname = $opt{f}; next; } case {$opt{l}} { $length = $opt{l}; next; } case {$opt{L}} { $location = $opt{L}; next; } case {$opt{i}} { $infile = $opt{i}; next; } case {$opt{d}} { $dirname = $opt{d}; next; } case {$opt{h}} { usage(); exit; } }
Otherwise, once I add "else" option at the last of "switch" statement its look not working for any options. Its look like the program will be pass to else fucntion, as examlple :
switch ($_) { case {$opt{1}} { read_structure_type1($opt{1}); next; } case {$opt{2}} { read_structure_type2($opt{2}); next; } case {$opt{3}} { read_structure_type3($opt{3}); next; } case {$opt{f}} { $fldname = $opt{f}; next; } case {$opt{l}} { $length = $opt{l}; next; } case {$opt{L}} { $location = $opt{L}; next; } case {$opt{i}} { $infile = $opt{i}; next; } case {$opt{d}} { $dirname = $opt{d}; next; } else {usage(); exit; } }

In reply to 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.