Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re^7: Smartmatch alternatives

by Laurent_R (Abbot)
on Dec 18, 2013 at 15:55 UTC ( #1067646=note: print w/replies, xml ) Need Help??

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, @_; }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1067646]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (10)
As of 2016-10-21 09:35 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (288 votes). Check out past polls.