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

update

> 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 http://stackoverflow.com/questions/5279917/why-doesnt-this-smart-match-work )

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)


In reply to Re: Smartmatch alternatives (updated) by LanX
in thread Smartmatch alternatives by cavac

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.