<?xml version="1.0" encoding="windows-1252"?>
<node id="20628" title="Re: A simple Comparison" created="2000-06-30 17:11:57" updated="2005-08-11 14:15:27">
<type id="11">
note</type>
<author id="2675">
btrott</author>
<data>
<field name="doctext">
If you compare them using &lt;i&gt;eq&lt;/i&gt; or &lt;i&gt;==&lt;/i&gt;, all
you're doing is comparing their values as references. And
since they're two different objects--ie. not references
to the same object--they're two different references. So
they won't be equal.&lt;p&gt;

To do a proper object comparison, you'll need to write a
method that compares two of your objects. One possibility
would be to serialize the objects and compare the serialized
strings:

&lt;code&gt;
    my $obj1 = new Obj;
    my $obj2 = new Obj;

    ## The two objects above are now equal, let's say.
    ## Serialize them, then compare the serialized
    ## data.

    use Storable qw/freeze/;
    if (freeze($obj1) eq freeze($obj2)) {
        ## They're the same.
    }
&lt;/code&gt;

In fact, you could even use [overload] to overload
the comparison operator so that the proper comparison
happens automagically:

&lt;code&gt;
    package Obj;
    use Storable qw/freeze/;
    use overload '==' =&gt; \&amp;compare;

    sub compare { return freeze($_[0]) eq freeze($_[1]) }
&lt;/code&gt;

Now you can just say:

&lt;code&gt;
    if ($obj1 == $obj2) {
        # They're the same.
    }
&lt;/code&gt;</field>
<field name="root_node">
20627</field>
<field name="parent_node">
20627</field>
</data>
</node>
