-
Notifications
You must be signed in to change notification settings - Fork 61
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
fix string comparisons with $] to use numeric comparison instead #136
fix string comparisons with $] to use numeric comparison instead #136
Conversation
The proposed patch interpolates and numifies both the left and right hand sides (eg I habitually do such comparisons without interpolating either side - ie |
As mentioned in the commit message, older versions of perl had floating point values that couldn't be directly compared to the expected numbers. Converting to a string then back to a number forces the value to have the expected float value. This only impacts perl versions prior to 5.8 though, so it's no longer a real concern. But some people continue to use that form out of habit or an excess of caution. Comparing to a string on the RHS is pointless, but the patch just maintained the values that were previously in the code. It would be better to change them to numeric values. |
Oh, yes - and it also won't matter whether the LHS is The key thing (from which I was distracted) is that it has to be a numeric comparison, not a string comparison. All good - and thank you for taking the time to clarify. |
Yes, I've updated my core patches to do numeric comparisons, to avoid confusing things more.
Well, actually:
The bug that |
4fd044e
to
9544d51
Compare
Duh .... oh, yes. Finally got it through my thick skull that, on those old perls, |
The fix follows Zefram's suggestion from https://www.nntp.perl.org/group/perl.perl5.porters/2012/05/msg186846.html > On older perls, however, $] had a numeric value that was built up using > floating-point arithmetic, such as 5+0.006+0.000002. This would not > necessarily match the conversion of the complete value from string form > [perl #72210]. You can work around that by explicitly stringifying > $] (which produces a correct string) and having *that* numify (to a > correctly-converted floating point value) for comparison. I cultivate > the habit of always stringifying $] to work around this, regardless of > the threshold where the bug was fixed. So I'd write > > use if "$]" >= 5.014, warnings => "non_unicode"; This ensures that the comparisons will still work when Perl's major version changes to anything greater than 9.
9544d51
to
af1feb7
Compare
The fix follows Zefram's suggestion from
https://www.nntp.perl.org/group/perl.perl5.porters/2012/05/msg186846.html
This ensures that the comparisons will still work when Perl's major version changes to anything greater than 9.