相关疑难解决方法(0)

在子处理程序中清除XML Twig

我正在使用XML :: Twig解析大型XML文件(60GB +)并在OO(Moose)脚本中使用它.我正在使用该twig_handlers选项在读入内存后立即解析元素.但是,我不确定如何处理Element和Twig.

在我使用Moose(和OO)之前,我的脚本看起来如下(和工作):

my $twig = XML::Twig->new(
  twig_handlers => {
    $outer_tag => \&_process_tree,
  }
);
$twig->parsefile($input_file);


sub _process_tree {
  my ($fulltwig, $twig) = @_;

  $twig->cut;
  $fulltwig->purge;
  # Do stuff with twig
}
Run Code Online (Sandbox Code Playgroud)

现在我就这样做了.

my $twig = XML::Twig->new(
  twig_handlers => {
    $self->outer_tag => sub {
      $self->_process_tree($_);
    }
  }
);
$twig->parsefile($self->input_file);

sub _process_tree {
  my ($self, $twig) = @_;

  $twig->cut;
  # Do stuff with twig
  # But now the 'full twig' is not purged
}
Run Code Online (Sandbox Code Playgroud)

问题是,我现在看到我错过了清除 …

xml perl xml-twig

7
推荐指数
1
解决办法
115
查看次数

标签 统计

perl ×1

xml ×1

xml-twig ×1