X BOL wishing you a very and Happy New year

Alternative content

Perl way to check if an array contains values

Perl is always is known for their flexibility (There is more than one way to do it).

Followings are the quick way to check if a value exist in an array.

do_something if 'flour' ~~ @ingredients   # ~~ operand.   BEWARE: it is broken.

do_something
if grep {$_ eq 'flour'} @ingredients # grep (slower than 'any')

do_something
if any {$_ eq 'flour'} @ingredients # List::MoreUtils / Util::Any

do_something
if any(@ingredients) eq 'flour'   # use syntax 'junction';

do_something
if @ingredients->contains('flour')   # added with autobox