Re: Need dependency-free way of capturing verbose function output in a variable

[email protected] (Aristotle Pagaltzis)
Newsgroups perl.cpan.workers
Message-ID <[email protected]>
* Zefram <[email protected]> [2015-07-19 20:35]:
> Aristotle Pagaltzis wrote:
> > There is no way I can think of doing this with the select-based
> > approach, nor with dup/reopen without involving XS;
>
> […] DESTROY on a blessed object […]

D’oh. Insufficient caffeine.

> Your "local *STDOUT" is a valid approach where applicable. Preferable to
> any End-like mechanism in those cases. It incidentally leaves *STDOUT{IO}
> empty, so that an explicit close is no longer required before the reopen.

Which is the whole point, of course: the original STDOUT FH for fd 1 sticks
around on the stack along with the rest of the glob and the FH in the fresh
glob gets opened with a different fd. So there’s no need to either close or
reopen fd 1 (which I was unaware has to happen in that order). Which is also
what makes the whole charade invisible at the libc level.

(Incidentally it can be onelinered: open local *STDOUT, '>', \(my $out = ''))

So to ask the question I was getting at but didn’t actually ask: given the
code in File::Path and James’ goal of re-/writing some tests for it, do you
consider this approach sufficient for the purpose?

-- 
Aristotle Pagaltzis // <http://plasmasturm.org/>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.