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.