pipe を使用する代わりに、常に Perl の grep を使用することをお勧めします。
@lines = `zcat $file_list2`; # move output of zcat to array
die('zcat error') if ($?); # will exit script with error if zcat is problem
# chomp(@lines) # this will remove "\n" from each line
foreach $i ( @contact_list ) {
print "$i\n";
@ar = grep (/$i/, @lines);
print @ar;
# print join("\n",@ar)."\n"; # in case of using chomp
}
最善の解決策は、zcat を呼び出すのではなく、zlib ライブラリを使用することです:
http://perldoc.perl.org/IO/Zlib.html
use IO::Zlib;
# ....
# place your defiiniton of $file_list2 and @contact list here.
# ...
$fh = new IO::Zlib; $fh->open($file_list2, "rb")
or die("Cannot open $file_list2");
@lines = <$fh>;
$fh->close;
#chomp(@lines); #remove "\n" symbols from lines
foreach $i ( @contact_list ) {
print "$i\n";
@ar = grep (/$i/, @lines);
print (@ar);
# print join("\n",@ar)."\n"; #in case of using chomp
}