Logo

Programming-Idioms

History of Idiom 12 > diff from v2 to v3

Edit summary for version 3 by :

Version 2

2015-05-06, 21:04:47

Version 3

2015-07-31, 18:58:31

Idiom #12 Check if list contains a value

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

Idiom #12 Check if list contains a value

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

Code
# To check an array for a value:
print "Found 'foo'\n" if grep { $_ eq 'foo' } @a_list;

# To check a map for a value:
print "Found 'bar'\n" if exists $map{bar};
Comments bubble
The inside of the curly braces for a hash(map) reference is automatically stringified.