Thanks to all who contributed.

I tried stephen's solution and it works nicely (using 5.6.0).

It is a tad faster than my tempfile solution (in the test shown below, 8% faster). And it looks more Perlish.

Rudif
#!/usr/bin/perl -w use strict; use File::Find; use File::Path; use File::Slurp; use Pod::Select; use IO::Scalar; use Benchmark; my $dir = "c:/perl/lib/Pod"; my %podstrings; timethese(10, { 'Tmpfile' => sub { %podstrings = (); findTmpfile(); # printf "%d\n", scalar keys %podstrings; }, 'TieStdout' => sub { %podstrings = (); findTieStdout(); # printf "%d\n", scalar keys %podstrings; }, }); sub findTmpfile { find ( sub { return if -d; my $tmpfile = "$dir/tmpfile.txt"; return if $File::Find::name eq $tmpfile; podselect {-output => $tmpfile}, $File::Find::name; if (-s $tmpfile) { $podstrings{$File::Find::name} = scalar read_file($tmpfile +); } unlink $tmpfile if -f $tmpfile; }, $dir); } sub findTieStdout { find ( sub { return if -d; my $output_string = ''; tie *STDOUT, 'IO::Scalar', \$output_string; podselect $File::Find::name; untie *STDOUT; if ($output_string) { $podstrings{$File::Find::name} = $output_string; } }, $dir); } __END__ Benchmark: timing 10 iterations of Tmpfile, findTieStdout... Tmpfile: 123 wallclock secs (120.08 usr + 2.71 sys = 122.80 CPU) @ + 0.08/s (n=10) TieStdout: 103 wallclock secs (102.45 usr + 0.82 sys = 103.27 CPU) @ + 0.10/s (n=10)

In reply to Re: Could I redirect stdout back into my script? by Rudif
in thread Could I redirect stdout back into my script? by Rudif

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.