Just downloaded 5.9.4 and love the new switch statement (especially the smart matching that comes with it). A notable difference from C traditions is that you do not need to break out of the block to avoid falling through to the next </code>case</code>.
given($data) { when (1) { say 'one' ; }; ## no "break" needed when (2) { say 'two' ; }; default { say 'something else'; }; }
The Perldoc states that you can still fall through to the next when using continue. It should probably point out that this is fundamentally different from falling through in C, because the following condition(s) are still being checked.
# this code does not work ! # it will say "something else" given($data) { when (1) { continue; }; when (2) { say 'one or two' ; }; default { say 'something else'; }; }
Of course, above example makes not much sense, but a straight port from C code would probably end up like that. The Perl way to write it (using smart matching) is more like
# this works, is shorter and easier to read given($data) { when ([ 1, 2]) { say 'one or two' ; }; default { say 'something else'; }; }
The Imp of the Perverse still wonders if it is possible to directly "goto" (maybe that's a hint right there...) the next block, skipping the when check.

In reply to Falling through Perl 5.10 switch statement by Thilosophy

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.