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)

In reply to Re: build regular expression from scalar? by jeffa
in thread build regular expression from scalar? by shapi003

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.