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

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

Thread Previous | Thread Next
Leon Timmermans
June 30, 2015 18:19
Re: extraneous autovivification (foreach (@$x), keys(%$x), ...)
Message ID:
On Tue, Jun 30, 2015 at 6:55 PM, Eric Brine <> wrote:

> The difference between foreach and push is that foreach imposes an lvalue
> context on its list and push does not.

> foreach needs to do this so you can do << $_ = uc($_) for @names; >>. <<
> sub foo { } foo(@$x) >> will similarly evaluate @$x as an lvalue context,
> autovivifying $x.
> I realize this doesn't answer your question.

foreach needs force lvalue context to the elements, inheriting the
lvalueness to the underlying arrayref is an accident of implementation IMO.
Not sure how extensive the backwards compatibility consequences would be of
changing this though.


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