develooper Front page | perl.perl5.porters | Postings from June 2015

Re: extraneous autovivification (foreach (@$x), keys(%$x), ...)

Thread Previous | Thread Next
From:
Eric Brine
Date:
June 30, 2015 19:03
Subject:
Re: extraneous autovivification (foreach (@$x), keys(%$x), ...)
Message ID:
CALJW-qHsJzV1pR2Mf2g+Jwum2jGCBwCJF7YvBc0_pwPHQ7AdxA@mail.gmail.com
On Tue, Jun 30, 2015 at 2:46 PM, Christian Millour <cm.perl@abtela.com>
wrote:

> is it the same accident of implementation that autovivifies intermediary
> levels when deep rooting in a data structure, even in pure rvalue context ?
> e.g.
>
> $ perl -MData::Dump -E'dd $x; $y = $x->{a}[1]{b}; dd $x'
> undef
> { a => [undef, {}] }
> $ perl -MData::Dump -E'dd $x; $z = $x->{a}{b}{c}; dd $x'
> undef
> { a => { b => {} } }
> $
>
> (arguably, the assignments above could set $y and $z to undef without
> autovivifying anything...)
>
>
That particular case is handled by adding << no autovivification; >>

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