http://www.perlmonks.org?node_id=1067646


in reply to Re^6: Smartmatch alternatives
in thread Smartmatch alternatives

OK, to work correctly, the first element of the array passed to any needs to be false. There are two ways of doing it, I tested both ways, but then I made the mistake of removing both ways from my post. It can be done either as in the update I made in my post above (prepending a 0 to the list passed to any) or by changing the any function as follows:

sub any (&@) { my $code_ref = shift; unshift @_, 0; reduce { $a or $code_ref->(local $_ = $b) } @_; }
Thank you Rolf for your remark.

Update: It could also be done this way, perhaps the best one:

sub any (&@) { my $code_ref = shift; reduce { $a or $code_ref->(local $_ = $b) } 0, @_; }