I'm storing a hash references from a threads to a shared @stories variable, and then can't access them.
my @stories : shared= ();
sub blah {
my %stories : shared=();
<some code>
if ($type=~/comment/) {
$stories{"$id"}="$text";
$stories{"$id"}{type}="$type";
lock @stories;
push @stories, \%stories;
}
}
# @stories is a list of hash references which are shared from the threads;
foreach my $story (@stories) {
my %st=%{$story};
print keys %st; # <- printed "8462529653954"
print Dumper %st; # <- OK
my $st_id = keys %st;
print $st_id; # <- printed "1"
print $st{$st_id}; # <- printed "1/8"
}
print keys %st works as expected but when i set in to a variable and print, it returns "1".
Could you please advice what I'm doing wrong. Thanks in advance.
$st_id = keys %stis the same as$st_id = scalar(keys %st), meaning set$st_idto the number of keys in the hash%st. - mobmy %st=%{$story}is making a copy of the hash? Any change you make to%stare not reflected in the original hashref. - cjm