스레드의 공유 참조 정보를 공유 @stories 변수에 저장하고 액세스 할 수 없습니다.hashref에서 해시 값을 가져올 수 없습니다.
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 % st'는'$ st_id = scalar (keys % st)'와 동일합니다. 이것은 해시'% st'의 키 수에'$ st_id '를 설정하는 것을 의미합니다. – mob
$ st_id가 열쇠가 될 것으로 기대합니다. 즉, 8462529653954. –
'my % st = % {$ story} '가 해시 복사본을 만들고 있다는 것을 알고 계십니까? '% st'에 대한 변경 사항은 원래 hashref에 반영되지 않습니다. – cjm