Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: XML::Twig - Filtering and duplexing output to multiple output files

by Discipulus (Canon)
on Nov 12, 2014 at 08:06 UTC ( [id://1106955]=note: print w/replies, xml ) Need Help??


in reply to [SOLVED] XML::Twig - Filtering and duplexing output to multiple output files

Hello ateague,
You had the right answer from Loops, i want to add only few words about your last question: "Is there a way to conditionally split target elements off into separate files and duplicate elements "outside" the target element to separate files without having to read the input file multiple times?" Even without a good module to multiplex the output you have no need to re-read the file. You can just build your custom print sub:
sub print_dup { foreach my $fh ( @previously_opened_handle_for_write ) { print {$f +h} @_ } }

You can also review similar question here at perlmonks as this one or my naive approch

HtH
L*
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
  • Comment on Re: XML::Twig - Filtering and duplexing output to multiple output files
  • Download Code

Replies are listed 'Best First'.
Re^2: XML::Twig - Filtering and duplexing output to multiple output files
by mirod (Canon) on Nov 12, 2014 at 14:14 UTC

    The problem in this case is the flush method, which does some light magic to output the parts of the tree that haven't been output yet, and then updates the state of the XML::Twig object (so the next call to flush Just Works™). You can't call it twice in a row, with 2 different filehandles, it wouldn't work. That's why using IO::Tee is a brilliant idea.

      obviously the author is right!
      See indeed the docs about flush

      You cannot hack it using print or sprint because they have to be used AFTER parse. lesson learned. Thanks.

      L*
      There are no rules, there are no thumbs..
      Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Log In?
Username:
Password:

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

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

    No recent polls found