Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^3: trapping -w warnings

by tphyahoo (Vicar)
on Nov 24, 2006 at 13:54 UTC ( #585873=note: print w/ replies, xml ) Need Help??


in reply to Re: Re: trapping -w warnings
in thread trapping -w warnings

I liked this enough that I bookmarked this in my delicious collection -- helped me debug a nasty problem.

I did things slightly differently though -- more localized, I think.

{ local $SIG{__WARN__} = sub { my @warnings = @_; foreach my $warning (@warnings) { print "got a warning: $warning\n"; } }; eval {'' =~ /$re/ }; }
cheers.


Comment on Re^3: trapping -w warnings
Download Code
Replies are listed 'Best First'.
Re^4: trapping -w warnings
by bart (Canon) on Nov 24, 2006 at 18:47 UTC
    AFAIK $SIG{__WARN__} is only ever called with one parameter: the current warning. So your loop is most likely useless.

    You can print each warning as it comes along. But what I did was collect the warnings first so you can print them out as a block. That may be useful if you want just one block, for example when printing warnings in a HTML page on a web server.

Re^4: trapping -w warnings
by tphyahoo (Vicar) on Feb 20, 2007 at 15:28 UTC
    On second thought, I don't think I needed that eval block. This works fine too.
    use strict; use warnings; { local $SIG{__WARN__} = sub { my @warnings = @_; foreach my $warning (@warnings) { warn "in handleEncoding, got a warning: $warning\n"; } }; warn "blee"; warn "blah"; warn "bloo"; }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2015-07-30 02:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (269 votes), past polls