Logo

Programming-Idioms

History of Idiom 12 > diff from v69 to v70

Edit summary for version 70 by dland:
New Perl implementation by user [dland]

Version 69

2019-09-26, 14:50:05

Version 70

2019-09-26, 14:54:15

Idiom #12 Check if list contains a value

Check if list contains a value x.
list is an iterable finite container.

Illustration

Idiom #12 Check if list contains a value

Check if list contains a value x.
list is an iterable finite container.

Illustration
Extra Keywords
array vector
Extra Keywords
array vector
Imports
List::Util 'first'
Code
print "ok\n" if first {$_ eq 'needle'} @haystack;
Comments bubble
grep() will find all the elements that match... in a large list this may waste time. first() will return true as soon as the element is found.
Doc URL
https://perldoc.perl.org/List/Util.html