Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Using XML::Writer, how can I output to a file AND to the console?

by GrandFather (Cardinal)
on Dec 13, 2012 at 22:38 UTC ( #1008739=note: print w/ replies, xml ) Need Help??


in reply to Using XML::Writer, how can I output to a file AND to the console?

Open a file handle on a string:

use strict; use warnings; use XML::Writer; my $outputStr; open my $output, '>', \$outputStr; my $writer = new XML::Writer(OUTPUT => $output); $writer->startTag("greeting", "class" => "simple"); $writer->characters("Hello, world!"); $writer->endTag("greeting"); $writer->end(); close $output; print $outputStr;

Prints:

<greeting class="simple">Hello, world!</greeting>

Having captured the output to a string you can print where ever you want and as many times as you want.

Update helps to copy and paste the right stuff!

True laziness is hard work


Comment on Re: Using XML::Writer, how can I output to a file AND to the console?
Select or Download Code
Re^2: Using XML::Writer, how can I output to a file AND to the console?
by envinyater (Initiate) on Dec 14, 2012 at 14:37 UTC
    It works, Thank you :)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2014-07-28 23:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (210 votes), past polls