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';
|
---|
In Section
Seekers of Perl Wisdom