Having trouble with XML::Twig when used in a loop. Here is my code:
sub twig {
+ # use twig to manipulate elements
my $infile = shift ;
my $processed = FALSE ;
our $twigObject = XML::Twig->new (
twig_handlers => {
'TABLE' => \&get_tab,
'CTOC-ChapterTOC' => \&del_chaptoc,
'CTOC-ChapterTOCList' => \&del_chaptoc,
'STOC-SectionTitleTOC' => \&del_chaptoc,
},
keep_atts_order => 1,
keep_encoding => 1,
pretty_print => "indented",
) ;
my $logname = LOGD . "/conv_logfile.txt" ;
open(LOG, ">> $logname" ) || die(
"Can't open \'$logname\'.\nStopped " );
$twigObject->parsefile_inplace($infile, '.bak') || die(
"WTF!! Something went wrong with the 'parse' " .
"of \'$infile\'.\nStopped $!\n") ;
$twigObject->flush() ;
+ # output back to original XML after Mods
undef($twigObject) ;
close(\*LOG) ;
return(0) ;
+ # back to main
}
It seems to work fine except when sent a 2nd filename, the output suddenly goes to STDOUT instead of the $infile. Any ideas what is happening here, Mirod?