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

Hash key creation for non-lvalue use

Thread Next
From:
Ed Avis
Date:
July 21, 2016 14:25
Subject:
Hash key creation for non-lvalue use
Message ID:
loom.20160721T162339-1@post.gmane.org
Unexpectedly this causes $h{a}{b} to be created as an empty hash, although I
thought I was doing read-only access.

    use 5.022;
    use warnings;
    use strict;
    use Data::Dumper;
    my %h;
    if (not $h{a}{b}{c}) {
       say Dumper \%h;
    }

Is this the longstanding grandfathered-in inconsistency in autovivification,
or have I misunderstood what's meant to happen?

-- 
Ed Avis <eda@waniasset.com>


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