我是一个全新的 Perl 新手,正在为我的第一个 Perl 脚本寻求帮助
我有一些 30-50GB 的大文件,它们的构造是这样的 - 数百万列和数千行:
A B C D E 1 2 3 4 5 6 7 8 9 10
A B C D E 1 2 3 4 5 6 7 8 9 10
A B C D E 1 2 3 4 5 6 7 8 9 10
A B C D E 1 2 3 4 5 6 7 8 9 10
A B C D E 1 2 3 4 5 6 7 8 9 10
A B C D E 1 2 3 4 5 6 7 8 9 10
A B C D E 1 2 3 4 5 6 7 8 9 10
我想删除“A”列和“C”列,然后是数字列的三分之一,所以“3”列和“6”列,然后是“9”列,直到文件末尾。空格分隔。
我的尝试是这样的:
#!/usr/local/bin/perl
use strict;
use warnings;
my @dataColumns;
my $dataColumnCount;
if(scalar(@ARGV) != 2){
print "\nNo files supplied, please supply file name\n";
exit;
}
my $Infile = $ARGV[0];
my $Outfile = $ARGV[1];
open(INFO,$Infile) || die "Could not open $Infile for reading";
open(OUT,">$Outfile") || die "Could not open $Outfile for writing";
while (<INFO>) {
chop;
@dataColumns = split(" ");
$dataColumnCount = @dataColumns + 1;
#Now remove the first element of the list
shift(@dataColumns);
#Now remove the third element (Note that it is now the second - after removal of the first)
splice(@dataColumns,1,1); # remove the third element (now the second)
#Now remove the 6th (originally the 8th) and every third one thereafter
#NB There are now $dataColumnCount-1 columns
for (my $i = 5; $i < $dataColumnCount-1; $i = $i + 3 ) {
splice($dataColumns; $i; 1);
}
#Now join the remaining elements of the list back into a single string
my $AmendedLine = join(" ",@dataColumns);
#Finally print out the line into your new file
print OUT "$AmendedLine/n";
}
但我收到了一些奇怪的错误:
- 它是说它不喜欢我在 for 循环中的 $1,我添加了一个“我的”,这似乎使错误消失但没有其他人的代码似乎在这里包含一个“我的”,所以我不确定是什么继续。
全局符号“$i”需要在 Convertversion2.pl 第 36 行显式包名。全局符号“$i”需要在 Convertversion2.pl 第 36 行显式包名。全局符号“$i”需要在 Convertversion2.pl 第 36 行显式包名. 全局符号 "$i" 需要在 Convertversion2.pl 第 36 行显示包名。
- 另一个错误是:Convertversion2.pl 第 37 行的语法错误,靠近“@dataColumns;” Convertversion2.pl 第 37 行,“1)”附近的语法错误
我不确定如何纠正这个错误,我想我快到了,但不确定语法错误到底是什么,不确定如何修复它。
先感谢您。