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

[perl #127712] defined on HashofHash defines an element in the hash

Thread Previous | Thread Next
Tony Cook via RT
March 14, 2016 22:31
[perl #127712] defined on HashofHash defines an element in the hash
Message ID:
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.

You can avoid this behaviour by using the autovivication module from CPAN.


[1] that autovivication doesn't always respect lvalue vs rvalue

via perlbug:  queue: perl5 status: new

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