in reply to Re: parsing multiple xml files with xml::twig
in thread parsing multiple xml files with xml::twig

thanks, yes i did have use strict and warnings enabled, Im not sure its a scoping issue as the $twig is a global and it does run without giving errors, just not the results I expected!
if I put all the sub code into the foreach loop I still get the same problem, namely that the last file is the only one which is apparently parsed: I missed some bits of code out before as I didnt think they were relevant and was trying to avoid inflating the post with unimportant details.. heres the fuller version:
#! /usr/bin/perl -wT use strict; use warnings; use Fcntl; use Getopt::Long; use POSIX; use XML::Twig; ### UNTAINT ENVIRONMENT, SUPPLIED FILENAMES #code to untaint env, filames here my $twig; my ($xmlfile, $ctlfile, $config); my (@assm_header, @chain_header, @xmlfiles); my %assm_header = (); my %assm_line = (); my %pdb_line = (); my %chains = (); my %chain_header = (); ### HANDLE COMMAND LINE OPTIONS # code to handle Getopt::long here @xmlfiles = qw(file1.xml file2.xml); foreach my $xfile (@xmlfiles) { $twig = new XML::Twig( twig_roots => { 'pdb_entry/pdb_code' => \&pdb_entry, 'pdb_entry/total_asm' => \&pdb_entry, 'pdb_entry/asm_set/assembly' => \&assembly,}); # &parse_twig($xfile); # sub code now inserted below ## sub code folded into here if ($twig->safe_parsefile($xfile) == 0) { die "Failed to parse $xfile: $@"; } my $root = $twig->root; my @params = $root->children('pdb_entry'); $twig->purge; $twig->dispose; } ... handler code

result is file2 gets parsed and output, no sign of file1.. ;+(