次のようなリストを含むテキスト ファイルがあります。
test1:test2
test3:test4
test5:test6
そして、それをハッシュでインポートしたいと思います(左の単語をキーとして、右の単語を値として.
私のコードは次のようなものです:
open FILE1, "text_file_with_words.txt" or die;
my %hash;
while (my $line=<FILE1>) {
chomp($line);
(my $word1,my $word2) = split /:/, $line;
$hash{$word1} = $word2;
}
use Data::Dumper;
print Dumper \%hash;
出力を下回っています:
$VAR1 = {
'test1' => 'test2',
'test5' => 'test6',
'test3' => 'test4'
};
さて、以下に示すように、最終的に出力を拡張するためにコードを変更する方法がわかりません。
$VAR1={
'test2' =>'test6'=>'test4'
};
誰かがこの出力を得るのを手伝ってくれますか?