Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^7: fall through switch/case in perl

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


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

Yes, but that's not equivalent to the OP's code.

Makeshifts last the longest.

Replies are listed 'Best First'.
Re^8: fall through switch/case in perl
by tachyon (Chancellor) on Sep 07, 2004 at 01:33 UTC

    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

      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://388898]
help
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found