我编写了一个perl代码,用于根据一个条件过滤XML。它是错误输出的消息"分段错误(Core Dumped)"带2GB输入文件。请参阅以下代码。任何输入都会有所帮助。
use strict;
use warnings;
use XML::Twig;
use Tie::File;
use XML::Parser;
my $SOURCEFILE=$ARGV[0];
my $TAGVALUE=$ARGV[1];
my $FILELOCATIONIN=$ARGV[2];
my $twig = new XML::Twig( twig_handlers => { TRADE => \&TRADE } );
$twig->parsefile($FILELOCATIONIN.'/'.$SOURCEFILE.'.xml');
$twig->set_pretty_print('indented');
$twig->print_to_file($FILELOCATIONIN.'/'.$SOURCEFILE.'.xml');
sub TRADE {
my ( $twig, $TRADE ) = @_;
foreach my $c ($TRADE)
{
#added delete in place of cut
#$TRADE->cut
$c->delete($TRADE) unless
$c->att('origin') eq $TAGVALUE
;
}
}
答案 0 :(得分:1)
使用->parsefile_inplace();
my $twig = new XML::Twig( twig_handlers => { TRADE => \&TRADE } );
$twig->parsefile_inplace($FILELOCATIONIN.'/'.$SOURCEFILE.'.xml');