in reply to build regular expression from scalar?

I would prefer to use such a program like so:
./monitor.pl -add -remove
but since that would surely involve an if-else of some kind, how about a usage such as this:
./monitor.pl -action ADD -action REMOVE
instead? Especially since Getopt::Long will stuff all -action arguments into an array for you. If this is acceptable for you, then feel free to mangle the following skeleton. Since you wanted to use a regular expression, how about we bring Tie::Hash::Regex along for the ride. Hope you like Pod::Usage as well. ;)

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<This program> 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

Oh, buy the way ... i really tried to avoid any if's or unless's by replacing them with and's and or's. I don't normally do that, as it's not always apparent what's really going on, but i thought you might enjoy Another Way To Do It. ;)

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)