in reply to why are hex values not numbers?

It's not just about being decimal or hexadecimal, since "1_1" == 1_1 is false (thanks haukex for mentioning the digit separator). I'm not sure if this is enough of a reason, but obtaining the same value with or without the quotes only works when you can stringify and turn into a number (numberify?) back and forth without changing either the string or the number. For example you wouldn't obtain the original string in map { "$_" } map { 0+$_ } "0x16"; if "0x16" was interpreted as 22.

Now "Don't use a string as a number if the number won't give you the same string" could have been a pretty good safety net, if perl didn't allow some oddities like "4 ever" being interpreted as the number 4. And print "equal" if '12.9999999999999999' == 13 prints "equal" on my version of perl.

Edit: you don't get your original string either with leading 0. print "Different" if "042" ne 0+"042";. "042" is 42 but 042 is 34, so once again if "042" had the same numeric value as a bare 042, it wouldn't stringify back to the original string.

Replies are listed 'Best First'.
Re^2: why are hex values not numbers?
by Eily (Monsignor) on Sep 27, 2016 at 17:11 UTC

    Following my last edit, I realized there's a good reason why using a string as a number is not always the same as simply removing the quotes. It's so that if you ask for user input, the user can type "042", or select this value in a form that pads its numbers with 0, and you'll still get the value the user meant to send rather than 34. I guess having "042" != 042 for this reason but "0x16" == 0x16 is more surprising than only having decimal numbers work this way.