in reply to fall through switch/case in perl
It's way overkill for your particular problem, but for commplicated situations, @switch_foo can contain references to subs, making it quite powerful (if a little slow).my @switch_foo = ("a","b","c",...); for ($var) { my $junk = shift; while ($junk > 0) { print $switch_foo[$junk]); $junk--; } }
In practice, however, if your algorithm needs a switch equivalent, you're better off re-thinking your algorithm.
Update: fixed the code so that it works!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: fall through switch/case in perl
by Anonymous Monk on Sep 07, 2004 at 15:23 UTC | |
by radiantmatrix (Parson) on Sep 07, 2004 at 15:40 UTC | |
by Anonymous Monk on Sep 07, 2004 at 15:59 UTC | |
by radiantmatrix (Parson) on Sep 07, 2004 at 18:21 UTC | |
by demerphq (Chancellor) on Sep 14, 2004 at 12:09 UTC | |
by Anonymous Monk on Sep 07, 2004 at 23:11 UTC | |
|