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.


In reply to Re: why are hex values not numbers? by Eily
in thread why are hex values not numbers? by perl-diddler

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.