in reply to Re: Objects as hash keys?
in thread Objects as hash keys?
One caveat:
package MyObj; sub new { bless {}, shift; } sub test { print("test\n"); } package main; my $o = MyObj->new(); my %hash; $hash{$o} = "This is my object"; foreach (keys(%hash)) { print("$_\n"); # MyObj=HASH(0x1abefc0) print("$hash{$_}\n"); # This is my object $_->test(); # Can't locate object method "test" via package # "MyObj=HASH(0x1abefc0)" (perhaps you forgot to # load "MyObj=HASH(0x1abefc0)"?) at script.pl line 26 }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Objects as hash keys?
by artist (Parson) on May 17, 2005 at 17:15 UTC |