Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

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

by ioannis (Abbot)
on Oct 12, 2005 at 04:59 UTC ( #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? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2022-11-30 21:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?