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

Re: [perl #133809] Perl silently adds a key to hash

Thread Previous | Thread Next
Deven T. Corzine
July 14, 2019 04:31
Re: [perl #133809] Perl silently adds a key to hash
Message ID:
On Sat, Jul 13, 2019 at 6:36 PM Dan Book <> wrote:

> Yes. Full stop. Tons of code relies on autovivification.
> -Dan

Of course tons of code relies on autovivification.  It's an awesome feature
and I certainly wasn't suggesting taking it away.  That would be a terrible

I was suggesting avoiding *unnecessary* autovivification, nothing more.
For example, if you have "if ($x->{$a}{$b}{$c}{$d}) {...}" and $x->{$a}{$b}
does not exist, I'm suggesting NOT autovivifying $x->{$a}{$b} and
$x->{$a}{$b}{$c} in the process of checking whether $x->{$a}{$b}{$c}{$d} is
true or false -- which is what happens by default now.  Under what
circumstances would that be helpful?

On the other hand, if you store a value, that is *necessary*
autovivification that should absolutely happen.  For example,
"$x->{$a}{$b}{$c}{$d}++" should definitely autovivify $x->{$a}{$b} and
$x->{$a}{$b}{$c}, because that's the only way to store a value in
$x->{$a}{$b}{$c}{$d}.  It's the "read-only" style of access I'm talking
about possibly changing, not the normal, required autovivification that
everyone relies on all the time.


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