在这里,我想将每行中的数据打印为3个单独的值,并将“:
”作为分隔符。该文件BatmanFile.txt
的详细信息如下:如何从文件中获取每行的数据?
Bruce:Batman:[email protected]
Santosh:Bhaskar:[email protected]
而且我预计产量为:
Bruce
Batman
[email protected]
Santosh
Bhaskar
[email protected]
执行脚本后的产量为:
Bruce
Batman
[email protected]
Bruce
Batman
[email protected]
请给我解释一下我是什么在这里输入:
use strict;
use warnings;
my $file = 'BatmanFile.txt';
open my $info, $file or die "Could not open $file: $!";
my @resultarray;
while(my $line = <$info>) {
#print $line;
chomp $line;
my @linearray = split(":", $line);
push(@resultarray, @linearray);
print join("\n",$resultarray[0]),"\n";
print join("\n",$resultarray[1]),"\n";
print join("\n",$resultarray[2]),"\n";
}
close $info;
或美国'unshift'把它放在开头。 – Sobrique
谢谢@Sobrique和Mathias。 – sbk