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

Re: [perl #88740] RFE: allow length(undef)=>0 (w/no warnings)

Thread Previous | Thread Next
From:
Linda W
Date:
July 3, 2012 18:16
Subject:
Re: [perl #88740] RFE: allow length(undef)=>0 (w/no warnings)
Message ID:
4FF3996E.2050803@tlinx.org



I don't care that much -- convenience wise, I'd would have preferred
the length of an undef return the 0 without the warning -- since with many
programs, a warning is treated the same as an error...

I.e. I'd rather a function like length always return a number -- like doing
a safe conversion from 'any' (defined or not) => number (in numeric 
context)...

But I could probably argue the opposite point of view just as 
logically...so...eh!
I don't care that much...
;-)


Jesse Luehrs via RT wrote:
> undef in numeric context evaluates to 0, so your example of summing up a
> bunch of lengths will still work identically (although the warning that
> is generated is now "Use of uninitialized value in addition (+)" instead
> of "Use of uninitialized value in length". Also, if you want to suppress
> the warning, previously you had to do "(defined($str) && length($str))
> || 0", where now you can do just "length($str) || 0", since passing
> undef to length no longer warns. I'm inclined to close this ticket,
> unless anyone can see anything here that should be done.
>
> -doy
>   


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