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 }
In reply to Re^2: Objects as hash keys?
by ikegami
in thread Objects as hash keys?
by artist
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |