in reply to Re: Multiple If Selections
in thread Multiple If Selections

If you're going to go with this approach to setting up/executing the dispatch, one suggestion:

Change

if( $line =~ m/(Job|File|Image)/ )
to
my $re = join '\|', keys %dispatch; if ( $line =~ m/$re/ )
so that you won't have to manually update the regex every time a case is added/removed/renamed. Changing the dispatch table and forgetting to update that regex would otherwise seem like a very easy way to introduce bugs which will leave you scratching your head for hours as you stare at the dispatch table and the called sub trying to figure out why they don't work together.

Replies are listed 'Best First'.
Re^3: Multiple If Selections
by bobf (Monsignor) on Jan 07, 2008 at 18:26 UTC

    Excellent suggestion++. You forgot the capturing parentheses, though, so instead of wondering why the dispatch table and the subs are working together you'll be wondering why $1 isn't what you think it is. :-)

    Change

    my $re = join '\|', keys %dispatch; if( $line =~ m/$re/ )
    to either
    my $re = '(' . join( '|', keys %dispatch ) . ')'; if( $line =~ m/$re/ )
    or
    my $re = join( '|', keys %dispatch ); if( $line =~ m/($re)/ )