Like japhy said, look into Carp. However, it sounds like that isn't what you're looking for...are you saying that none of your die messages include any line/filename info? In that case, this suggests that your die() message strings all end in '\n'. If you remove those newlines, you'll get that information. Alternatively, if you replace each die() with croak(), the '\n' won't prevent a line-number from appearing (although it will push that information onto the next line). As an alternative, rather than going line-by-line through your code, just adding this should give you what you want:
BEGIN { $SIG{__DIE__} = sub { my $string = shift; chomp($string); my ($package, $file, $line) = caller; die "$string [at $file, line $line]\n" unless ($package eq 'Carp'); } }
Modifying $SIG{__DIE__} like this changes how all of your die() calls behave (including croak(); that last bit with the 'unless' is in there to keep the output from getting too ugly). If you want the same sort of thing for warn() and carp(), you can modify $SIG{__WARN__}.
Update: I had croak() and carp() switched in the last paragraph there (thanks premchai21).
Update++:Also, tilly's post above this one (about checking $^S) applies to what I'm doing here. Here's how I think this ought to be taken into account (with confess thrown in for a complete trace of the call-stack (thanks again tilly)):
Note that I'm going on what I just read in perlvar more than on experience with $^S. Also, using confess in $SIG{__DIE__} like this produces a little weirdness in the output when you use croak in the main code, that I don't know how to fix.BEGIN { $SIG{__DIE__} = sub { my $string = shift; chomp($string); my ($package, $file, $line) = caller; confess "$string\n" if ((defined ($^S)) and not $^S); } }
-- Frag.
In reply to Re: dying() more informatively
by frag
in thread dying() more informatively
by thpfft
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |