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

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

Thread Next
From:
Christian Millour
Date:
June 30, 2015 12:54
Subject:
extraneous autovivification (foreach (@$x), keys(%$x), ...)
Message ID:
55929163.9070407@abtela.com
Hi,

does
	foreach ( @$x ) { ... }
really need to autovivify $x to an empty array ref if $x is undef ? In 
other contexts, @$x happily evaluates to an empty list without 
autovivification :

$ perl -MData::Dump -E'dd $x; push @a, @$x; dd $x; frobnicate for @$x; 
dd $x'
undef
undef
[]
$

similarly, keys(%$x) / values(%$x) / each(%$x) autovivify an undef $x to 
an empty hash ref.

Do these autovivifications have a purpose or could they be be avoided / 
optimized away ?

TIA,

--Christian

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