私はまったく新しい 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分の1、つまり「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 が気に入らないと言っています。「my」を追加したため、エラーが解消されたようですが、他の for コードには「my」が含まれているようには見えないので、何が原因かわかりません。進んでいます。
グローバル シンボル "$i" には、Convertversion2.pl 行 36 で明示的なパッケージ名が必要です。 グローバル シンボル "$i" には、Convertversion2.pl 行 36 で明示的なパッケージ名が必要です。 . グローバル シンボル "$i" には、Convertversion2.pl 行 36 で明示的なパッケージ名が必要です。
- もう 1 つのエラーは次のとおりです。「@dataColumns;」付近の Convertversion2.pl 行 37 の構文エラーです。Convertversion2.pl 行 37、「1)」付近の構文エラー
このエラーを修正する方法がわかりません。ほぼ完了したと思いますが、構文エラーの正確な内容がわからず、修正方法もわかりません。
前もって感謝します。