in reply to regex switch trouble

I have used the Switch module myself in the past but found a couple of bugs with it (i.e. you have to fully specify all matches with a 'm' - m/match/ rather than /match/ else you get really strange errors, and line numbers are out when the compiler errors).

I prefer to use the recommended method in the Camel (see also perldoc -q switch):

SWITCH: foreach ($1) { m/^fred$/ && do {$replace_text='wilma'; last SWITCH}; m/^wilma$/ && do {$replace_text='fred'; last SWITCH}; do { die "Unknown check: $_\n" } }

The code doesn't look as elegant as with the switch module, but I have had far fewer problems (and I will try Switch again sometime as I like it in principle).

Replies are listed 'Best First'.
Re^2: regex switch trouble
by blazar (Canon) on Jun 24, 2007 at 09:52 UTC
    (and I will try Switch again sometime as I like it in principle).

    Wait for C<given>: guaranteed to be impressive, and very perlish in its own way, albeit not 5ish at all.