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

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

Thread Previous | Thread Next
From:
Deven T. Corzine
Date:
July 14, 2019 04:31
Subject:
Re: [perl #133809] Perl silently adds a key to hash
Message ID:
CAFVdu0QXoN3YLtZLDKPFq7_KPoj55oPE=neHkzMEXjyhW4e4oA@mail.gmail.com
On Sat, Jul 13, 2019 at 6:36 PM Dan Book <grinnz@gmail.com> 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
idea.

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.

Deven

Thread Previous | 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