最近需要提取出文本文件中某几列的数据,简单写了一下脚本:
use strict;
my $read_file = "1.txt";
my $write_file = "2.txt";
open my ($fhin), '
open my ($fhout),'>', $write_file or die "Can't open file: $!";
while(){ #也可以在foreach循环中使用类似的语法读取整个文件内容到内存,将while改为foreach
chomp;
my @line=split /,/,$_;
my ($col1,$col2)=@line[0,1];
print $fhout "$col1,$col2\n";
}
close $fhout;
close $fhin;
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/24802932/viewspace-711869/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/24802932/viewspace-711869/

190

被折叠的 条评论
为什么被折叠?



