in reply to given/when one case prefixes another
This works in Strawberry 5.10.1.4, but I don't know how 'proper' it is; frankly, it looks a bit hinky to me.
>perl -wMstrict -lE "for my $s qw(a b c d) { given ($s) { when ('a') { say 'a'; continue; } when ('b') { say 'b'; continue; } when (/[ab]/) { say ' after a or b'; } say 'neither a nor b'; when ('d') { say 'd'; } default { say qq{other: '$_'}; } } } " a after a or b b after a or b neither a nor b other: 'c' neither a nor b d
BTW: I couldn't get the goto approach to work: Perl experiences a 'panic: goto' attack.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: given/when one case prefixes another
by moritz (Cardinal) on Apr 26, 2011 at 09:03 UTC | |
by AnomalousMonk (Archbishop) on Apr 26, 2011 at 15:46 UTC |