in reply to Re: trapping -w warnings
in thread trapping -w warnings
Alternatively, you can do your checking inside the $SIG{__WARN__} sub.$re = '[\w-]'; my @warnings; { local $SIG{__WARN__} = sub { push @warnings, shift }; eval {'' =~ /$re/ }; } if($@) { print "error: $@\n"; } else { foreach my $warning (@warnings) { print "Got a warning: $warning"; } }
Note how you need a semicolon after some "blocks" for it to work: after the assignment of the anonymous sub to $SIG{__WARN__}, and after the eval block, at least if any statement comes right after it — which you forgot.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: trapping -w warnings
by Anonymous Monk on Nov 26, 2003 at 07:44 UTC | |
by bart (Canon) on Nov 26, 2003 at 07:49 UTC | |
|
Re^3: trapping -w warnings
by tphyahoo (Vicar) on Nov 24, 2006 at 13:54 UTC | |
by bart (Canon) on Nov 24, 2006 at 18:47 UTC | |
by tphyahoo (Vicar) on Feb 20, 2007 at 15:28 UTC |