in reply to Re: GetOpts not working:
in thread GetOpts not working:
Here's a similar way, but instead of using the experimental switch, I use a dispatch table. Note this destroys @ARGV in the process and definitely is only an example and shouldn't be used in production code without much more work.
use warnings; use strict; my ($file, $thing); my %arg_table = ( -f => sub { $file = shift; }, -t => sub { $thing = shift; }, default => sub { die "bad param"; }, ); while (my @args = splice @ARGV, 0, 2){ if (defined $arg_table{$args[0]}){ $arg_table{$args[0]}->($args[1]); } else { $arg_table{default}->(); } } print $file if defined $file; print $thing if defined $thing;
|
|---|