in reply to Re: Referencing built-ins
in thread Referencing built-ins
But if a given option takes an argument, wouldn't this be the way to go:{ my %opt; getopts("hf:d:") || die HELP(); sub opt_h { exists $opt{h} ? 1 : 0 } sub opt_f { exists $opt{f} ? 1 : 0 } sub opt_d { exists $opt{d} ? 1 : 0 } }
There's just that little issue about remembering to leave off the $ sigil when testing the options -- some habits are hard to unlearn (but "use strict" will cover that).{ my %opt; getopts("hf:d:") || die HELP(); sub opt_h { exists $opt{h} ? 1 : 0 } sub opt_f { exists $opt{f} ? $opt{f} : '' } sub opt_d { exists $opt{d} ? $opt{d} : '' } } if ( opt_f eq "foo" ) { ... } # usw, etc.
|
|---|