Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: range comparison in given

by Lotus1 (Chaplain)
on Jul 10, 2013 at 14:21 UTC ( #1043478=note: print w/ replies, xml ) Need Help??


in reply to range comparison in given

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


Comment on Re: range comparison in given
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (16)
As of 2014-07-30 20:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (240 votes), past polls