develooper Front page | perl.perl5.porters | Postings from September 2016

Re: pounding the smartmatch drum

Thread Previous | Thread Next
Paul "LeoNerd" Evans
September 6, 2016 14:51
Re: pounding the smartmatch drum
Message ID:
On Mon, 5 Sep 2016 21:23:54 -0500
David Nicol <> wrote:

> I agree. We already have a way to "ask the lhs whether it matches" and
> that system is called method dispatch.
> sub UNIVERSAL::DumbMatch{0}
> sub DumbMatchOnOdd::DumbMatch{ [0,1]->[$_[1] % 2] }
> ...
> $SomeObjectOrOther->DumbMatch($PretzelPattern) and say "got a
> pretzel";

Well, almost. That is a bit dirty and pollutes the UNIVERSAL namespace.

Nicer would be if perl had notations for "try to call this method but
if it doesn't exist, yield some sentinel falsey value like undef or
empty list".

Paul "LeoNerd" Evans      |  |

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