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.. ;+(


In reply to Re^2: parsing multiple xml files with xml::twig by diomedea
in thread parsing multiple xml files with xml::twig by diomedea

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.