Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: Smartmatch alternatives (updated)

by LanX (Canon)
on Dec 17, 2013 at 15:25 UTC ( #1067482=note: print w/ replies, xml ) Need Help??

in reply to Smartmatch alternatives

Before smartmatch was introduced, the answer was to use grep in boolean context, cause it in scalar context it returns the grep-count.

And if speed matters take any from List::MoreUtils . Same interface like grep but immediately returns 1 after first match.

DB<107> @a=(a..f)x10 DB<108> use List::MoreUtils qw/any/ DB<109> grep { "a" eq $_ } @a => ("a", "a", "a", "a", "a", "a", "a", "a", "a", "a") DB<110> 0+ grep { "a" eq $_ } @a => 10 DB<111> 0+ any { "a" eq $_ } @a => 1


> want to axe smartmatch because it is too confusing,

The first documentation of smartmatch came with a ridiculous long table which was very hard to remember and IIRC not commutative (i.e A ~~ B wasn't B ~~ A).

( see also )

My (a?) catch phrase was "I'm not smart enough for smart match".

Attempts to fix this destroyed the faith in it's reliability.

It's rather paradox if you "like smartmatch" with all implicit mechanisms but at the same time you state "downright stupid is the implicit use of $_" ???

We certainly need a better way to introduce and test no features...

well actually we have do have use feature!!!

I wouldn't object if say was made standard ...

Cheers Rolf

( addicted to the Perl Programming Language)

Comment on Re: Smartmatch alternatives (updated)
Select or Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (14)
As of 2014-08-21 14:47 GMT
Find Nodes?
    Voting Booth?

    The best computer themed movie is:

    Results (136 votes), past polls