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

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

Thread Previous | Thread Next
From:
Ed Avis
Date:
July 3, 2012 09:53
Subject:
RE: Smartmatch two cents (was... List::Util... when...)
Message ID:
3473E52454418E4094496BFAAC199441015097C8@wcl-exch01.wcl.local
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 <eda@waniasset.com>

______________________________________________________________________
This email has been scanned by the Symantec Email Security.cloud service.
For more information please visit http://www.symanteccloud.com
______________________________________________________________________

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About