Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^8: fall through switch/case in perl

by tachyon (Chancellor)
on Sep 07, 2004 at 01:33 UTC ( [id://388904]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://388904]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (2)
As of 2024-04-24 23:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found