|
[pm-h] print on warning tip: msg#00022lang.perl.perl-mongers.houston
I had a problem where I needed to see what a few values where if I got a 'use of unititalized value' warning, but I'm parsing a logfile that can easily be over a million lines long (Solaris' nfslog), so I couldn't really just print everything a million times. I found this is perfaq8: BEGIN { $SIG{__WARN__} = sub{ print STDERR "Perl: ", @_; }; $SIG{__DIE__} = sub{ print STDERR "Perl: ", @_; exit 1}; } This hints at an answer, but the problem is that I need to print a lexically scoped variable. So I changed things up a bit: our $warnflag; BEGIN { $SIG{__WARN__} = sub{ print STDERR "Perl: ", @_; $warnflag=1;}; } And in my code: print "username is $username\tid is $id, UID is $UID\n" if $warnflag; $warnflag =0 if $warnflag; Hope that helps someone. And if there's a better way to do this, I'd love to see that, too. Paul
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | [pm-h] Bayou project (or: you had too much time on your hands anyway, Wade), Paul Archer |
|---|---|
| Next by Date: | [pm-h] Deja vu, G. Wade Johnson |
| Previous by Thread: | [pm-h] Bayou project (or: you had too much time on your hands anyway, Wade), Paul Archer |
| Next by Thread: | Re: print on warning tip, Kevin Shaum |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |