develooper Front page | perl.perl5.porters | Postings from August 2005

Re: ++ turns undef into 0 first

Thread Previous | Thread Next
From:
Yitzchak Scott-Thoennes
Date:
August 19, 2005 03:19
Subject:
Re: ++ turns undef into 0 first
Message ID:
20050819101930.GA2784@efn.org
On Fri, Aug 19, 2005 at 11:41:08AM +0200, Rafael Garcia-Suarez wrote:
> On 8/18/05, Peter Scott <Peter@psdt.com> wrote:
> > This recently bit me:
> > 
> > $ perl -wle 'print 42 if defined($h{foo}++)'
> > 42
> > 
> > Now, before thousands of you reach for the flamethrowers, yes, I know
> > - now - that this is documented.  I found it in perlop right where it
> > ought to be:
> > 
> > | undef is always treated as numeric, and in particular is changed to 0
> > | before incrementing (so that a post-increment of an undef value will
> > | return 0 rather than undef).
> 
> This was documented by Hugo as change 19014 :
> http://public.activestate.com/cgi-bin/perlbrowse?patch=19014
> Hugo, any comment on this ?

I remember a borderline acerbic discussion here; perhaps someone could
read the archives and summarize what was said, rather than everyone
restating the same opinions?

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