Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Range Operator in If Statement

by TJPride (Pilgrim)
on Jan 05, 2012 at 05:29 UTC ( #946325=note: print w/ replies, xml ) Need Help??


in reply to Range Operator in If Statement

If the ranges you're matching on are consecutive, you could do something like this:

use strict; use warnings; for (-4, 1, 7, 12, 89, 54, 13, 104) { if ($_ < 1 || $_ > 64) { print "$_ outside.\n" } elsif ($_ <= 8) { print "$_ 1-8\n"; } elsif ($_ <= 16) { print "$_ 9-16\n"; } elsif ($_ <= 32) { print "$_ 17-32\n"; } elsif ($_ <= 64) { print "$_ 33-64\n"; } }


Comment on Re: Range Operator in If Statement
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (10)
As of 2015-07-29 16:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (265 votes), past polls