Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

$twig->flush causing output to stdout?

by Joe.Orcino (Initiate)
on Mar 24, 2015 at 21:46 UTC ( [id://1121223]=perlquestion: print w/replies, xml ) Need Help??

Joe.Orcino has asked for the wisdom of the Perl Monks concerning the following question:

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?

Replies are listed 'Best First'.
Re: $twig->flush causing output to stdout?
by GotToBTru (Prior) on Mar 25, 2015 at 02:01 UTC

    When subroutine call contains a second filename? Or when subroutine is called 2nd time?

    Dum Spiro Spero

      Sorry that wasn't clear; I meant it does this when I call this as a subroutine a second time (specifying a new filename).

        Then this s dependant on how you called the subroutine, especially in which way you specified the new filename. You should show us that code as well.
Re: $twig->flush causing output to stdout?
by Anonymous Monk on Mar 24, 2015 at 23:29 UTC

    It seems to work fine except when sent a 2nd filename, the output suddenly goes to STDOUT instead of the $infile.

    2nd filename?

    Where in the code you posted is this second filename?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1121223]
Approved by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-04-23 23:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found