我有以下代码可以从我正在使用的文本文件中删除行。但是,它实际上并没有删除我想要的行。我在这里做了很多测试,并确认如果我得到正确的行号,它将删除这些行。但是,这$.
似乎是在复制实际的行号(当我在上面打印时,它说实际行数是原来的两倍!)
#!/usr/bin/perl
# find_company_codes.pl
use strict;
use warnings;
use diagnostics;
use Tie::File;
my $split_file = "//server/folder/splits_table.txt";
# remove fields where only MAS has rollcall
my @file;
my @lines;
tie @file, 'Tie::File', $split_file or die $_;
foreach (@file) {
@lines = split(",",$_);
next if $lines[0] eq "ESDB Link Processing Reg-Prd-CCD";
next if $lines[2] ne "";
next if $lines[3] ne "";
next if $lines[4] ne "";
next if $lines[5] ne "";
next if $lines[6] ne "";
splice(@file, $.,1);
}
untie @file;
ps - 我知道我可以使用它,但是,我认为在这种情况下使用 'Tie::File` 会更直接一点。