in reply to Re: Redirect HTML::TreeBuilder to file
in thread Redirect HTML::TreeBuilder to file

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; } }

Replies are listed 'Best First'.
Re^3: Redirect HTML::TreeBuilder to file
by marto (Cardinal) on Sep 25, 2018 at 13:23 UTC

    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.

        As I said, your open and print works fine, you just copied an example someone gave you, which prints a string to a file. You need to print the content of your variable to the file, rather than a fixed string. Did you look at the documentation I linked to? This is what I mean about copying and pasting code without trying to understand what it does.