develooper Front page | perl.perl5.porters | Postings from June 2012

Re: Smartmatch two cents (was... List::Util... when...)

Thread Previous | Thread Next
June 29, 2012 12:17
Re: Smartmatch two cents (was... List::Util... when...)
Message ID:
On 29 juin, 12:54, (Ed Avis) wrote:
> Father Chrysostomos via RT <perlbug-followup <at>> writes:
> >Oh, and let’s deprecate smartmatch while we are at it.
> I agree, and for the one case where smartmatch is useful in practice:
>     if ($x ~~ @values) { ... }
> add a new operator 'in' borrowed from Python
>     if ($x in @values) { ... }
> which does an 'eq' comparison with each item in the list, stopping and returning
> true if one matches, false otherwise.
> I would gladly remove smartmatch from my code if Perl provided an 'in' keyword
> to replace it, which is the only thing I use smartmatch for anyway.

I agree with your statement, but the problem is that there is always
something to be added, for example: what about numeric values ? --> so
it seems reasonable to add an '==' comparison for numeric values, but
hey, we also want text that looks like a number to be treated like a
number, so we add '==' comparison for that, too, and so on... we finally arrive at the same mess with 'in' as we already have
with ~~.

Maybe two versions of 'in' might be in order, 'in_eq' for text
comparison and in_== for numeric comparison. But again, there is
probably a better way...

You see, it never stops.

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About