![]() |
|
Welcome to the Monastery | |
PerlMonks |
Re^15: why are hex values not numbers? (octal)by tye (Sage) |
on Oct 02, 2016 at 05:16 UTC ( #1173109=note: print w/replies, xml ) | Need Help?? |
This thread gave no valid reason. Well, most of the thread didn't even try to give a reason. But I think Re^2: why are hex values not numbers? got it right. I recall finding a bug in C code that misinterpreted IP addresses padded to look nice:
by interpreting octets with leading zeros as being in octal. Perl decided to require you to be explicit if you want to interpret a leading zero as indicating octal when interpreting a string. oct() is how to indicate that you want the leading zero to impact the base when interpreting a string as a number. I concur with the choice to have "010" == 10 and "010" != 010. And I can see how it could seem more consistent to have the interpretation of 0x and 0b fall along the same lines. But stepping away from that consistency, I agree with you that it would be good to transition Perl so that it becomes possible for "0x10" == 0x10 (and that such eventually becomes the default). And I would like to see similar changes so we get to where "1_000" == 1_000. Beyond just a foolish consistency, it could also be argued that when asking a user for a numeric value, you should not assume that the user is a programmer. So you should treat "012" as "12" because that is what a non-programmer would mean. And you could extend that argument to other number formats that are expected of programmers but not others, like "0x1A4". But I disagree with that conclusion. "012" is a valid way to write 12. "0x12" is not a valid way to write 0. - tye
In Section
Seekers of Perl Wisdom
|
|