Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: how to quickly tell if number is in an array

by ioannis (Abbot)
on Oct 12, 2005 at 04:59 UTC ( [id://499375]=note: print w/replies, xml ) Need Help??


in reply to how to quickly tell if number is in an array

While countless methods exist to test for membership in the list, it is worthy to remember the obvious: when checking for elemenet 0, we should not forget to test using defined. Here is an example, this time using first from List::Util:
use List::Util 'first'; my @arr = (1..2, 0, 4); my $num = 0; defined first {$_==$num} @arr and print 'found';

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-04-19 01:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found