문제

I need to process hundreds of xml files. I'm using XML::LibXML. I'm quite new to perl and I don't understand how to close the fist XML parsed file, before opening the new one

Example

use XML::LibXML;
my ($parser, $doc, $node);
foreach my $xmlfullname (@xmlfullnamearray) {
    $parser = XML::LibXML->new();
    $doc    = $parser->parse_file($xmlfullname);
    $node   = $doc->findnodes("/root/node");
    ...
}

Thanks to all, Riccardo

도움이 되었습니까?

해결책

By losing all references to it, which you already do by overwriting all the variables.

A little cleaner and clearer:

use XML::LibXML;

my $parser = XML::LibXML->new();

foreach my $xmlfullname (@xmlfullnamearray) {
    my $doc  = $parser->parse_file($xmlfullname);
    my $node = $doc->findnodes("/root/node");
    ...
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top