Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^3: my 'if' condition doesn't work, why?

by Athanasius (Archbishop)
on Nov 12, 2014 at 07:36 UTC ( [id://1106950]=note: print w/replies, xml ) Need Help??


in reply to Re^2: my 'if' condition doesn't work, why?
in thread my 'if' condition doesn't work, why?

shame that it's not standard Perl but instead requires an extra module

Well, you can get a similar result using List::Util, which is a core module:

#! perl use strict; use warnings; use List::Util 'any'; for my $n (0 .. 267) { print "$n\n" if any { $n == $_ } (40, 47, 76); }

Update: Fixed off-by-one error in the for loop range, thanks to AnomalousMonk.

Output:

17:34 >perl 1074_SoPW.pl 40 47 76 17:34 >

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2024-04-19 10:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found