I wrote a handler for warnings to give me some more info when things break. But if the warning handler makes things break as well, then obviously I don't want to use it. Is this code bad?
Update: This is under ActiveState Perl 5.6.1, on WinXP
$SIG{__WARN__} = \&mywarn; # ... sub mywarn { my $warning = shift; my $i = 0; open (WRNLOG, ">>Warnings.log") || warn "Can't open warnings log f +ile: $!"; # If open failed, output will be discarded print STDOUT "WARNING: $warning"; print WRNLOG "WARNING: $warning"; print STDOUT " Stack Trace:\n"; print WRNLOG " Stack Trace:\n"; while (caller($i)) { my (undef, $filename, $line, $sub) = caller($i); print STDOUT " $filename ($line) --- $sub\n"; print WRNLOG " $filename ($line) --- $sub\n"; $i++; } print STDOUT "\n"; print WRNLOG "\n"; }
---
A fair fight is a sign of poor planning.
In reply to Which signals are unsafe? by Sprad
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |