0

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

Riccardo79
  • 954
  • 4
  • 17
  • 35

1 Answers1

2

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");
    ...
}
ikegami
  • 367,544
  • 15
  • 269
  • 518