到目前为止匹配的线,我想出如何使用该Perl模块,,Text::CSV_XS
匹配从CSV文件中的行。 我需要帮助的是删除文件中的那一行。是否有捷径可寻?在这个模块中有没有办法做到这一点?去除使用CSV模块在Perl
use strict;
use warnings;
use Text::CSV_XS;
my @rows;
my $csv = Text::CSV_XS->new ({ binary => 1 }) or
die "Cannot use CSV: ".Text::CSV_XS->error_diag();
open my $fh, "<:encoding(UTF-16LE)", "Test.txt" or die "cannot open file: $!";
while (my $row = $csv->getline ($fh)) {
if ($row->[0] =~ m/ABCDE/)
{
print "We have a match, remove the line \n";
}
else
{
print "No match found\n";
}
}
$csv->eof or $csv->error_diag();
close $fh;
+1这也是我的建议。还有[Tie :: Array :: CSV](http://search.cpan.org/perldoc?Tie::Array::CSV),这似乎是最近更新的。 Tie :: CSV_File从2003年开始,可能会过时。 – TLP