Well, Perl has a tendency to take the attitude that it should warn when you are most likely doing something stupid, and to not to warn when you probably aren't. Thus you see things like "0 but true" NOT warning

C:\Temp>perl -we"print 0+'0 but true'" 0 C:\Temp>perl -we"print 0+'0 and true'" Argument "0 and true" isn't numeric in addition (+) at -e line 1. 0

Since I can't think of any remotely sane reason why one would do a string or numeric comparison other than '==' or 'eq' on a ref (ok, I lie, I can think of one, but its pretty sucky, that being that you can sort references into an arbitrary but repeatedable order using reference comparison), therefore it doesnt seem to me to be unreasonable to warn in these situations. Whereas 0+ implies the decision was intentional and not accidental, and overloading implies that the operation is specifically allowed, and '==' is the normal way for doing equivelency tests on refs, so you dont want to warn in those situations.

What would this really mean for the programmer? Well it means that when they want to violate the encapsulation that references provide and use an arbitrary value (the memory location of the ref) for something it probably shouldn't be used for they need to signal to the interpreter that they would like to blow their foot off, by using the 0+ disambiguation. IMO this would probably catch a few bugs, and maybe break some code that uses references as hashkeys without using the 0+ disambiguation, something that could itself be special cased, or probably better just be worked around with a 0+.

Anyway, I doubt any of this will ever happen, but I thought I would express what I consider to be the way it might make sense.

---
$world=~s/war/peace/g


In reply to Re^3: The trap of reference numification by demerphq
in thread The trap of reference numification by samtregar

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.