Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Well, what the first couple folks said doesn't actually answer your question... they were answering what *would* have been your question if you *had* had break statements... I don't know if the original post was updated after the fact or if they simply did not actually read it... whatever.

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

In reply to Re: fall through switch/case in perl by etcshadow
in thread fall through switch/case in perl by ykar

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (1)
As of 2024-04-24 15:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found