in reply to Re: Re: STDERR
in thread STDERR
A post that tells you how to tie a filehandle (or how to use Filter::Handle, or points you towards the existence of Filter::Handle, etc.) actually *should* help you to store prints to STDERR into an array. Try this:
@errors now holds two elements: "bar" and "foo".use Filter::Handle qw/subs/; my @errors; Filter \*STDERR, sub { push @errors, "@_"; () }; print STDERR "bar"; print STDERR "foo"; UnFilter \*STDERR;
If you read the Filter::Handle docs you'll find an example very much like this, under the head "Capturing Output".
Note that this doesn't work for XS code, and it doesn't catch errors written by warn. So in that sense using $SIG{__WARN__} or working with DBI to get the errors back the way you want them is the right way to go.
*However*, it's a useful technique to use, at times.
|
|---|