New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFE: allow length(undef)=>0 (w/no warnings) #11257
Comments
From perl-diddler@tlinx.orgThis is a bug report for perl from perl-diddler@tlinx.org, (Since I have yet to install 5.12, please excuse any ignorance of In 5.12, I believe, the behavior of length was changed from giving a When this was announced, I thought, "oh, that makes sense, how can you But in writing programs that use length, I have a different view -- in Example: Suppose I ask what is the length of the color orange. It makes The length function in this case is 'arbitrary', and I can see a $SIG{__WARN__} = and get 'clean' looking code to (for example) sum up the lengths NOTE: this is a clear example where 0 is the "correct" answer. I.e. if I would ASSERT, that most people would answer "0" -- not "undef" and Alternatively instead of using a SIG handler, one substitute: "( defined $str && length $str ) || 0" Now, in 5.12, there's no more warning to intercept -- it just returns "$str && length $str || 0" instead of the simple "length $str". So, actually, that's what I'm proposing as a fix, 'sorta' -- introduced use undef_has_length0; The shorter the name, the less obvious it is what it does. Unfortunately, on a personal level, my initial acceptance of this Perhaps this issue might be raised amongst a wider group a people Linda Walsh Flags: This perlbug was built using Perl 5.10.0 - Fri Jul 30 00:12:10 UTC 2010 Site configuration information for perl 5.10.0: Configured by abuild at Thu Sep 16 16:14:28 UTC 2010. Summary of my perl5 (revision 5 version 10 subversion 0) configuration: Locally applied patches: @INC for perl 5.10.0: Environment for perl 5.10.0: |
From @ap* Linda Walsh <perlbug-followup@perl.org> [2011-04-18 02:15]:
length $str // 0 |
The RT System itself - Status changed from 'new' to 'open' |
From @doyundef in numeric context evaluates to 0, so your example of summing up a -doy |
From perl-diddler@tlinx.orgI don't care that much -- convenience wise, I'd would have preferred I.e. I'd rather a function like length always return a number -- like doing But I could probably argue the opposite point of view just as Jesse Luehrs via RT wrote:
|
From @doyIn that case, closing. -doy |
From [Unknown Contact. See original ticket]In that case, closing. -doy |
@doy - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#88740 (status was 'resolved')
Searchable as RT88740$
The text was updated successfully, but these errors were encountered: