in reply to Prevent my STDERR logging in evals...

Just a guess: Did you tried to set $SIG{__WARN__} to an empty sub { } or to undef at the very beginning of the eval to catch the warnings?

Update: I thought now about a tiny test for this:
perl -e '$a=10; eval { $SIG{__WARN__} = sub {  }; $a->isa('foo')}; print "Eval: ", $@, "\n"'
or
perl -e '$a=10; eval { $SIG{__WARN__} = undef; $a->isa('foo')}; print "Eval: ", $@, "\n"'

Both have the warning still in $@. I can't say much about a tied STDERR but it looks pretty much that this isn't working. One another idea I had was to localise the STDERR typeglob inside eval:

perl -e '$a=10; eval { local *STDERR; print STDERR "Test\n"; $a->isa('foo'); }; print $@;'

While this still sets the warning inside $@ the message to STDERR isn't printed. It's worth a try.

Replies are listed 'Best First'.
Re^2: Prevent my STDERR logging in evals...
by ikegami (Patriarch) on May 07, 2008 at 22:23 UTC
    Close, but so wrong!
    • $SIG{__WARN__} should have been localized.
    • $SIG{__WARN__} doesn't hide the message from an exception such as $a=10; $a->isa('foo').
    • local *STDERR; simply replaces the text with the warning "print() on unopened filehandle STDERR".
    • Warnings don't set $@.
Re^2: Prevent my STDERR logging in evals...
by suaveant (Parson) on May 08, 2008 at 14:36 UTC
    Aha! Yes, I did redefine the sig handlers for warn and die and that is the problem. I'm not even sure why I did it any more this was written so long ago.

    Silly me... thanks!

                    - Ant
                    - Some of my best work - (1 2 3)