Update: Removed the unneeded nested foreach loop.

You can use foreach in place of given without the weird side effects. I adapted the following from an example at brian d. foy's blog about given/when.

use v5.10; use warnings; foreach ( 'a', 'z', 5..11 ) { when( /a/ ) { say "$_ : ", 'Matched an a' } when( [ 2..5 ] ) { say "$_ : Matched 2 through 5" } #line 7 when( [ 6..10 ] ) { say "$_ : Matched 6 through 10" } default { say "$_ : Matched nothing" } }
a : Matched an a Argument "z" isn't numeric in smart match at C:\b\perlmonks\switch.pl +line 7. z : Matched nothing 5 : Matched 2 through 5 6 : Matched 6 through 10 7 : Matched 6 through 10 8 : Matched 6 through 10 9 : Matched 6 through 10 10 : Matched 6 through 10 11 : Matched nothing

In reply to Re: range comparison in given by Lotus1
in thread range comparison in given by mrguy123

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.