in reply to Need help: Getopt
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;
|
|---|