I am assuming that you can do exactly the same in Perl using a ref command in conjunction with '=='.

Not quite, since ref returns the type of the reference, not its address. You'll need Scalar::Util's refaddr for the latter. By default, Perl references used in numeric context will return the memory address (perlref), however, if the Perl objects use operator overloading, this is no longer true - see my example here.

If you look at the Python docs, you'll see that if the class defines a __eq__ method, it is used for == comparisons, and the fallback is to check if it's the same object, i.e. it's basically the same behavior as Perl's operator overloading. Python's is is basically what BillKSmith implemented here (and it's the only "entirely correct" answer in this thread).

Note that the general concept of "does one object equal another" is actually a lot more difficult than it sounds. When are two database handles equal - when they connect to the same database, or they have the same state, and so on? When are two objects loaded through an ORM like DBIx::Class equal - when their primary key is equal, or when all of their fields are equal, and so on? In such cases it's easier to code a custom comparator instead of the class attempting to provide a sensible default.


In reply to Re: Python 'is' command by haukex
in thread Python 'is' command by betmatt

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.