ハッシュのハッシュに保存する値を収集しようとしていますが、perl がそれを行う方法についてちょっと混乱しています。したがって、次のようにハッシュのハッシュを作成します。
my %hash;
my @items;
#... some code missing here, generally I'm just populating the @items list
#with $currentitem items
while (<FILE>) { #read the file
($a, $b) = split(/\s+/,$_,-1);
$hash{$currentitem} => {$a => $b};
print $hash{$currentitem}{$a} . "\n";#this is a test and it works
}
上記のコードは機能しているようです。要点を言えば、$currentitem の値を保持する配列 @items があります。そして、私はこのようなことをしたい:
@test = keys %hash{ $items[$num] };
特定のアイテムのすべてのキーと値のペアを取得できるようにします。上記のコード行と同様に試しました
while ( ($key, $value) = each( $hash{$items[$num]} ) ) {
print "$key, $value\n";
}
次のようにハッシュを入力しようとしました:
$host{ "$currentcustomer" }{"$a"} => "$b";
私が出会ったさまざまなオンライン情報源によると、どちらがより正しいようです。それでも、そのハッシュ内のデータにアクセスできません...何かアイデアはありますか?