any#

True if the block returns true for at least one element.

תקציר#

my $bool = any { BLOCK } @list;
if ( any { length > 10 } @strings ) { ... }

For each element any sets $_ to that element and calls the block in scalar context. It returns true as soon as the block returns true for any element, without examining the rest. For an empty list it returns false.

מה מוחזר#

1 if any element satisfied the block, 0 otherwise.

דוגמאות#

warn "has empty"   if any { $_ eq '' } @values;
die  "has admin"   if any { $_->is_admin } @users;
my $ok = any { /^--help$/ } @ARGV;

הבדלים מן ה-upstream#

Fully compatible with upstream.

ראו גם#

  • all - require every element to match.

  • none - require no element to match.

  • first - return the matching element itself.