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

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

Thread Previous | Thread Next
Ed Avis
July 3, 2012 09:53
RE: Smartmatch two cents (was... List::Util... when...)
Message ID:
David Mertens asked:

>Why would "$a in %hash" be equivalent to "exists $hash{$a}"?

This is how it works in Python, and it seems natural in Perl too.
You could write '$a in values %hash' if you wanted that.
In my experience testing for hash membership by key is much more
common than by value, and '$a in %h' is a clearer way to express it
than 'exists $h{$a}', especially when dealing with hash references.

>PDL defines a method called "in"

Hmm.  I imagine that adding the new 'in' keyword would have to be
protected by 'use 5.6789' or similar.  It might lead to some interesting
clashes with subroutines called 'in'.  Such code would either have to
explicitly qualify it as PDL::in, or not have 'use 5.6789', or have
"no feature 'in'" to disable the builtin keyword.

Ed Avis <>

This email has been scanned by the Symantec Email service.
For more information please visit

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