in reply to Re^4: Smartmatch alternatives
in thread Smartmatch alternatives
If you don't have any, it is easy to implement it using the reduce function of List::Utils with something like this:
Update: the above line need to be this:
Or, better:sub any { my $code_ref = shift; reduce { $a or $code_ref->(local $_ = $b) } @_; }
which makes it possible to call it with a syntax similar to grep:sub any(&@) { my $code_ref = shift; reduce { $a or $code_ref->(local $_ = $b) } @_; }
<strike>print "true\n" if any { $_> 11 } qw /3 12 4 5 7/; # prints tru +e
print "true\n" if any { $_> 11 } 0, qw /3 12 4 5 7/; # prints true
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^6: Smartmatch alternatives
by LanX (Saint) on Dec 17, 2013 at 22:37 UTC | |
by Laurent_R (Canon) on Dec 18, 2013 at 00:08 UTC | |
by Laurent_R (Canon) on Dec 18, 2013 at 15:55 UTC |
In Section
Seekers of Perl Wisdom