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

Hash key creation for non-lvalue use

Thread Next
Ed Avis
July 21, 2016 14:25
Hash key creation for non-lvalue use
Message ID:
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 <>

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