Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Writing processed html from Html::Parser

by nglenn (Beadle)
on Jan 14, 2011 at 03:11 UTC ( [id://882277]=perlquestion: print w/replies, xml ) Need Help??

nglenn has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to process some html files with Html::Parser, and I want to write the processed text to new xml files. Placing a print statement in a handler prints to stdout, and it doesn't seem like it would be very efficient to pass a filename, open for appending, write the one tag to the file, and then close it again. Does anyone know a better way to do this?

  • Comment on Writing processed html from Html::Parser

Replies are listed 'Best First'.
Re: Writing processed html from Html::Parser
by Anonymous Monk on Jan 14, 2011 at 03:31 UTC
    with select
    use autodie; { open my($out), '>', 'out.xml'; my $saver = select $out; my $parser = HTML::Parser.... print ... # all output goes into $out; select $saver; } print "all output goes back into STDOUT";
    or with SelectSaver
    use autodie; use SelectSaver; { open my($out), '>', 'out.xml'; my $saver = SelectSaver->new($out); my $parser = HTML::Parser.... print ... # all output goes into $out; } print "all output goes back into STDOUT";
      Thanks! This works great.

Log In?
Username:
Password:

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

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

    No recent polls found