Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Prevent my STDERR logging in evals...

by mscharrer (Hermit)
on May 07, 2008 at 21:25 UTC ( [id://685333]=note: print w/replies, xml ) Need Help??


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)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://685333]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-19 05:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found