次の内容を含む 2 つのテキスト ファイルがあります。
FILE1.txt
dog
cat
antelope
FILE2.txt
1
2
Barry
私が達成したい出力は次のとおりです。
dog1
dog2
dogBarry
cat1
cat2
catBarry
antelope1
antelope2
antelopeBarry
彼らは私がそれについて行った方法です:
open (FILE1, "<File1.txt") || die $!;
open (FILE2, "<File2.txt") || die $!;
my @animals = (<FILE1>); #each line of the file into an array
my @otherStrings = (<FILE2>); #each line of the file into an array
close FILE1 || die $!;
close FILE2 || die $!;
my @bothTogether;
foreach my $animal (@animals) {
chomp $animal;
foreach my $otherString (@otherStrings) {
chomp $otherString;
push (@bothTogether, "$animal$otherString");
}
}
print @bothTogether;
私が行った方法はうまくいきますが、特に両方のファイルに数千行が含まれている可能性がある場合、それは最善の方法ではないと確信していますか?
おそらくハッシュを使用するために、これを行う最良の方法は何でしょうか?