Hello,
I'm trying to parse multiple xml files but i'm a bit stuck with something. The
$twig->parsefile("output_1.xml"); section of the below script work fine in parsing the file stated. However, I would like to parse all of the .xml files in the direcotry. I have tried writing each file into the code like so:
$twig->parsefile("output_1.xml" "output_2.xml" "output_3.xml");
And i've also tried using a wildcard like I would in bash like so :
$twig->parsefile("*.xml");
But none of these attempts work. How can I change the script so that all of the .xml files in the directory are parsed by the script? I appologise fr my lack of knowledge, i've only just started using Perl.
#!/bin/perl -w
use strict;
use XML::Twig;
my $twig = XML::Twig->new(
twig_handlers => {item => \&acct}
);
$twig->parsefile("output_1.xml");
sub acct {
my ($t, $elt) = @_;
for my $tag (qw(itemId title viewItemURL convertedCurrentPri
+ce)) {
print $elt->field($tag), "\n";
}
print "\n";
print "\n";
}