in reply to Re: OO Perl: after it creates 2nd object overwrites hash from the first
in thread OO Perl: after it creates 2nd object overwrites hash from the first

 Thanks a lot!! It works fine!!
 Now I have to understand what's making the difference 
  • Comment on Re^2: OO Perl: after it creates 2nd object overwrites hash from the first

Replies are listed 'Best First'.
Re^3: OO Perl: after it creates 2nd object overwrites hash from the first
by FunkyMonk (Bishop) on Aug 31, 2007 at 18:14 UTC
    Your version doesn't create a new hashref for each object. It just reuses the same one:
    my $self1 = {}; %{ $self1->{hash} } = (); print "$self1->{hash}\n"; %{ $self1->{hash} } = (); print "$self1->{hash}\n"; #Output: HASH(0x504f80) HASH(0x504f80)

    My use of {} creates a new hashref for both objects:

    my $self2; $self2->{hash} = {}; print "$self2->{hash}\n"; $self2->{hash} = {}; print "$self2->{hash}\n"; #Output: HASH(0x622bb0) HASH(0x504160)