in reply to Redirect HTML::TreeBuilder to file

To make print print to a file, just specify the special filehandle argument.
open my $out, '>', 'output.html' or die $!; print {$out} "This will be printed to the file.\n"; close $out;
($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Replies are listed 'Best First'.
Re^2: Redirect HTML::TreeBuilder to file
by TonyNY (Beadle) on Sep 25, 2018 at 13:12 UTC

    Hi choroba,

    Where would I put this in the code to build the tree?

    tried it here but it did not work:

    else { # If $node is not a reference, then it is just a piece of text # from the HTML file. # print $node, "\n"; open my $out, '>', 'output.html' or die $!; print {$out} "This will be printed to the file.\n"; close $out; } }

      Rather than just copy/paste stuff without understanding take a look at open and print. You've copied an example you were given which writes the string "This will be printed to the file", to the file... you know the line you commented out prints what you want to the screen.

        Thanks for your response marto but I ran the code with the line commented out first and it still printed the output on the screen before I added the open and print code.