in reply to Re: STDERR
in thread STDERR

Well, I obviously didn't ask the question very well, but your answer didn't help at all. Which is why I complained.

Let me give it another shot.

  1. How do ya catch the messages from DBI without letting them get to the screen?
  2. How do ya store the lines of STDERR into an array.
Linking to posts that show how to print STDERR to a file; how to tie a filehandle don't really help at all.

I mean, in the big picture, ALL the questions I've ever seen posted in this section could be answered by reading the man pages. Near as I can tell there's only two reasons to post a question to perlmonks: 1) shortcut the research so you can have more fun programming, and 2) ask the question outloud so others can learn from your learning.

So, if tieing a filehandle helps with populating my array some how, then I'd really appreaciate a hint; which is why I asked the question in the first place.

Replies are listed 'Best First'.
Re: Re: Re: STDERR
by btrott (Parson) on Dec 20, 2000 at 06:17 UTC
    I have a slight quibble with this (and because I wrote Filter::Handle :).

    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:

    use Filter::Handle qw/subs/; my @errors; Filter \*STDERR, sub { push @errors, "@_"; () }; print STDERR "bar"; print STDERR "foo"; UnFilter \*STDERR;
    @errors now holds two elements: "bar" and "foo".

    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.