in reply to fall through switch/case in perl
The short answer is that there isn't anything that does this very well, and in the same way as C does. The thing to understand is that switch statements in C are actually just well-written GOTO statements! Likewise, the best way to do this might be GOTOs (as bad as that might sound)... or just coding it explicitly, something like:
for ( $var ) { my $go; ($go || $_ == 10) and $go++, print "a"; ($go || $_ == 9 ) and $go++, print "b"; ($go || $_ == 8 ) and $go++, print "c"; ($go || $_ == 7 ) and $go++, print "d"; ($go || $_ == 6 ) and $go++, print "e"; ($go || $_ == 5 ) and $go++, print "f"; ($go || $_ == 4 ) and $go++, print "g"; ($go || $_ == 3 ) and $go++, print "h"; ($go || $_ == 2 ) and $go++, print "i"; ($go || $_ == 1 ) and $go++, print "j"; }
------------ :Wq Not an editor command: Wq
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: fall through switch/case in perl
by TimToady (Parson) on Sep 07, 2004 at 01:20 UTC | |
by Aristotle (Chancellor) on Sep 07, 2004 at 01:25 UTC | |
by BrowserUk (Patriarch) on Sep 07, 2004 at 01:46 UTC | |
by etcshadow (Priest) on Sep 07, 2004 at 02:52 UTC | |
by BrowserUk (Patriarch) on Sep 07, 2004 at 04:10 UTC | |
by etcshadow (Priest) on Sep 07, 2004 at 05:44 UTC | |
|