These are already implemented in List::MoreUtils. The trick is the & prototype:
sub any(&@) { my $cb = shift; $cb->() && return 1 for @_; 0 } sub all(&@) { my $cb = shift; $cb->() || return 0 for @_; 1 } if (all { $_ eq 'foo' } @array) { ... }
By the way, == is the wrong operator to compare against 'foo'.
== is the numerical comparison operator.
eq is the string comparison operator.
See perlop.
In reply to Re: array comparison
by ikegami
in thread array comparison
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |