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

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

Thread Previous | Thread Next
From:
Paul Johnson
Date:
June 30, 2015 20:02
Subject:
Re: extraneous autovivification (foreach (@$x), keys(%$x), ...)
Message ID:
20150630200245.GD22905@pjcj.net
On Tue, Jun 30, 2015 at 08:19:33PM +0200, Leon Timmermans wrote:
> 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.

  This surprising autovivification in what does not at first--or even
  second--glance appear to be an lvalue context may be fixed in a future
  release.

Yes, not exactly the same situation and, even if we want to, I also
wonder whether this could ever be fixed.

-- 
Paul Johnson - paul@pjcj.net
http://www.pjcj.net

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