in reply to Re^7: fall through switch/case in perl
in thread fall through switch/case in perl

As you say, it is not equivalent. To do that you need some extra checks at the top of the 'loop' ie

last unless /^\d+$/ and $_ <= 10;

It is almost certainly a silly way to do it in Perl anyway. It is even a rather suboptimal way to do it in C.....

for(i=0;i<var;i++) printf( "%c", 97+i ); /* C or perl */ print map chr,97..96+$var;

cheers

tachyon

Replies are listed 'Best First'.
Re^9: fall through switch/case in perl
by Aristotle (Chancellor) on Sep 07, 2004 at 03:25 UTC

    I don't mean the extra checks. I mean it doesn't preserve the semantics. Imagine if the OP's code didn't have the conditions in a strictly monotonic increasing or decreasing sequence, but in some completely random order. You couldn't emulate that simply by fiddling the conditions a little — you'd have to build a construct that's actually equivalent.

    Makeshifts last the longest.