./monitor.pl -add -remove #### ./monitor.pl -action ADD -action REMOVE #### use strict; use warnings; use Pod::Usage; use Getopt::Long; use Tie::Hash::Regex; our (%action,@action,$help); # %action is a look-up hash whose values are (mostly) sub refs tie %action, 'Tie::Hash::Regex'; %action = ( ADD => \&monitor_add, REMOVE => \&monitor_remove, DELETE => \&monitor_delete, ALL => sub {}, #hack: do-nothing anon sub ); GetOptions( 'action|a=s' => \@action, 'help|h|?' => \$help, ); $help and pod2usage(-verbose=>2); @action or pod2usage(-verbose=>1); # validate the actions $action{$_} or die "bad action: $_\n" for @action; # if ALL was specified, assign all actions to @action grep /ALL/, @action and @action = keys %action; # this is where the subs are actually called $action{$_}->() for @action; sub monitor_add { print "ADD thingy is being monitored\n" } sub monitor_remove { print "REMOVE thingy is being monitored\n" } sub monitor_delete { print "DELETE thingy is being monitored\n" } __END__ =head1 NAME monitor.pl - monitor ADD REMOVE and DELETE thingies =head1 SYNOPSIS monitor.pl -action ADD|REMOVE|DELETE Options: -action -a which action to perform (ADD REMOVE DELETE ALL) -help -h detailed help =head1 DESCRIPTION B monitors thingies. Currently it monitors ADD, REMOVE, and DELETE thingies. You may specify one of the three, or any combination. =head1 EXAMPLES 1 - monitor ADD things monitor.pl -action ADD 2 - monitor ADD and REMOVE things monitor.pl -action ADD -action REMOVE monitor.pl -a ADD -a REMOVE 3 - monitor all things monitor.pl -a ALL