Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Class::Std problem

by duckyd (Hermit)
on Dec 20, 2006 at 22:05 UTC ( [id://590999] : note . print w/replies, xml ) Need Help??


in reply to Class::Std problem

I don't think your problem has anything to do with Class::Std per se. You need to overload "eq" to compare your object ids. E.G.
#!/usr/local/bin/perl use strict; use warnings; my $manager1 = Manager->new({ id => 1 }); my $manager2 = Manager->new({ id => 1 }); my $manager3 = Manager->new({ id => 3 }); compare( $manager1, $manager2 ); compare( $manager1, $manager3 ); sub compare { my ( $obj1, $obj2 ) = @_; if ($obj1 eq $obj2) { print "They are the same object\n"; }else { print "They are different objects\n"; } } package Manager; use overload 'eq' => sub { $_[0]->{id} == $_[1]->{id} } ; sub new { my ( $class, $args ) = @_; $args ||= {}; return bless $args, $class; }
output:
They are the same object They are different objects