develooper Front page | perl.perl5.porters | Postings from January 2012

Re: [perl #107528] Autovivification should be ignored when testingfor existence

Thread Previous
From:
Paul Johnson
Date:
January 6, 2012 04:00
Subject:
Re: [perl #107528] Autovivification should be ignored when testingfor existence
Message ID:
20120106120005.GC2506@pjcj.net
On Thu, Jan 05, 2012 at 02:58:30PM -0800, Robert Colvin via RT wrote:
> On Thu Jan 05 08:18:43 2012, 
> zefram@fysh.org wrote:
> > Robert Colvin via RT wrote:
> > >But in my opinion if the 
> default behaviour is to create 
> the variable
> > >reference when I test for its 
> existence, that is a bug. 
> > 
> > It's not a bug.  The behaviour 
> is perfectly consistent across 
> operators.
> > "exists" does not create the 
> hash element that you ask it 
> about.
> > The autovivification applies to 
> the *hash* in which you looked.
> > 
> > -zefram
> > 
> 
> 
> indeed it may be consistent, 
> though it is ultimately 
> incorrect! in testing existence 
> the state of variables are 
> modified. exists should be a safe 
> operation and it is therefore 
> reasonable to expect that it 
> won't make any modifications 

From perldoc -f exists:

  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.

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

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About