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

Re: [perl #127712] defined on HashofHash defines an element in thehash

Thread Previous | Thread Next
Paul Johnson
March 15, 2016 15:52
Re: [perl #127712] defined on HashofHash defines an element in thehash
Message ID:
On Mon, Mar 14, 2016 at 03:31:02PM -0700, Tony Cook via RT wrote:
> On Mon Mar 14 09:45:35 2016, wrote:
> > Checking with defined for an Hash of Hash element defines the element
> > in the
> > hash, instead of returning undefined:The following code will reproduce
> > it: perl
> > -e 'if(defined($foo{"a"}{"b"})){ print "not
> > defined\n";}if(defined($foo{"a"})){
> > print "ERROR? now defined?\n";} ' I hope it is not a feature. tested
> > with perl
> > 5.20.2 under Linux
> This is a known problem[1], and is difficult to fix because the change would break existing code.

Break, in the sense of altering.  But this is the case for all bug
fixes.  Since the last century the following has appeared in perlfunc:

  This surprising autovivification in what does not at first--or even
  second--glance appear to be an lvalue context may be fixed in a future

Now, this bug has existed for a long time and therefore is in a slightly
different category to a bug in a new feature, for example, which gets
fixed a release or two later.  But are we seriously saying that we
cannot fix this now because, we assume, too much code would change

If that is the case, then the documentation should be updated to reflect
this policy.  If not, Tony makes it sound as though it is otherwise not
difficult to fix.  That was not my understanding, but if it is so, then
should we not fix it?

If we would still like to fix it but cannot at the moment, for some
other reason, then things stay as they are.

Which case do we have here?

Paul Johnson -

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