It is unclear what you are trying to do but making the assumption that the dump method will only write to a file handle and would like to avoid a temp file just use an IO::String object where you have *OUT. Dump will then happily dump into this. This is what IO::String was designed for.

use IO::String; my $io = IO::String->new; $tree->dump($io); $io->setpos(0); @lines = <$io>; # dump output in an array

About the only gotcha with IO::String objects is that if you write to one you end up at EOF (end of string) so in order to read all the data in you need to seek back to the begining (pos, setpos and seek all work). If you forget to do this it appears there is no data.....


In reply to Re: HTML::TreeBuilder. Redirect tree->dump to an array by tachyon-II
in thread HTML::TreeBuilder. Redirect tree->dump to an array by mm&mm

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.