Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
While the string eq operator can check for reference equivalence, the numeric == operator is preferred for this sort of check.

Sure. It is much more efficient. I only intended to let the OP know that the code he is maintaining might be doing something useful without operator overloading. (It turns out that I guessed right.)

By using the == instead of eq, you compare the addresses directly, rather than converting both operands to strings which happen to include identical character sequences.

Well, I wouldn't go as far as to say stringified references just "happen to include identical character sequences." They include identical character sequences because the same code produces those characters from the same input data.

They're functionally equivalent today, but I imagine someone may find some odd exploit involving stringified references.

An exploit? I would love to hear more about how you think someone might accomplish that. :-)

Yes, == is better than eq for checking reference equality. It's much faster. Use numerical comparison. Tell others to use numerical comparison. But, there is no reason to be paranoid about the construct. It isn't dangerous. It isn't deprecated. (afaik) It works fine; it's just slow.

P.S. I can even think of one good reason to use it. What if you have overridden '0+' and want to check for reference equality rather than the equality of two objects' overridden numification?

-sauoq
"My two cents aren't worth a dime.";

In reply to Re: Re: Re: Clawing my way out of operator overloading hell by sauoq
in thread Clawing my way out of operator overloading hell by skyknight

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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others wandering the Monastery: (14)
    As of 2019-10-18 14:27 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Notices?