The following simple program gives this error in Perl 5.8
and I don't understand why. I've searched high and low in
the newsgroups and this list and have tried many permutations
of things to no avail. Several snippets of code I found lead
me to believe that this should work. I'm obviously missing
something (besides some old favorite parts of my frontal
lobe).
Any help is appreciated:
Can't call method "id" on unblessed reference at s.pl line 23.
======================
#!/usr/local/bin/perl
use strict;
use threads;
use threads::shared;
my %Assoc : shared = ();
MAIN:
{
for (my $i=0;$i<10;$i++) {
my $f=new Foo($i);
share($f);
$Assoc{$i} = $f;
}
foreach my $f (values %Assoc) {
print $f->id() . "\n";
}
}
{
package Foo;
sub new {
my $proto=shift;
my $id=shift;
my $class=ref($proto) || $proto;
my $self = {
ID => $id,
};
bless($self,$class);
return $self;
}
sub id {
my $self=shift;
return $self->{ID};
}
}