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

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

Thread Previous | Thread Next
From:
Leon Timmermans
Date:
June 30, 2015 18:19
Subject:
Re: extraneous autovivification (foreach (@$x), keys(%$x), ...)
Message ID:
CAHhgV8jnCSFVyS0f8U6_nXMSW+t4M2i5BA1Mc3B65Ed8r-9D_w@mail.gmail.com
On Tue, Jun 30, 2015 at 6:55 PM, Eric Brine <ikegami@adaelis.com> 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.

Leon

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