I would use a dispatch table with a bunch of subroutines, one for each action. The dispatch table makes it easy to use the command line argument to call the proper bit of code. Simple example:
my %ACTION_NAMED = define_actions(); my $action = shift; # First argument my @args = @ARGV; # Remaining arguments if (exists $ACTION_NAMED{$action}) { $ACTION_NAMED{$action}->(@args); } else { $ACTION_NAMED{_default_}->(@args); } sub define_actions { return ( action1 => \&action1, action2 => \&action2, _default_ => \&usage, ); } sub action1 { ... } sub action2 { ... } sub usage { ... }
In reply to Re: What's the best way to make my script execute different sections without using goto?
by revdiablo
in thread What's the best way to make my script execute different sections without using goto?
by gctaylor1
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |