【发布时间】:2014-07-15 00:42:20
【问题描述】:
我做了这个功能来修改我的 csv 文件:
sub convert
{
# open the output/input file
my $file = $firstname."_lastname_".$age.".csv";
$file =~ /(.+\/)(.+\.csv)/;
my $file_simple = $2;
open my $in, '<', $file or die "can not read the file: $file $!";
open my $out, '>', $outPut."_lastname.csv" or die "can not open the o file: $!";
$_ = <$in>;
# first line
print $out "X,Y,Z,W\n";
while( <$in> )
{
if(/(-?\d+),(-?\d+),(-?\d+),(-?\d+),(-?\d+)/)
{
my $tmp = ($4.$5);
print $out $2.$sep.$3.$sep.$4.$sep.($5/10)."\n";
}
else
{print $out "Error: ".$_;}
}
close $out;
}
我想跳过前 3000 行,但我不知道怎么做,这是我第一次使用 perl。
谢谢。
【问题讨论】:
-
添加一个计数器,如果计数器
-
@Jens;我收到此错误 “strict subs”时不允许裸字“co”
-
您在哪一行得到错误?缺少变量 co 的 my 声明。
-
@Jens;没关系,这是我的错,我不明白你的回答,谢谢 :)
标签: algorithm perl parsing csv