in reply to dying() more informatively

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)):

BEGIN { $SIG{__DIE__} = sub { my $string = shift; chomp($string); my ($package, $file, $line) = caller; confess "$string\n" if ((defined ($^S)) and not $^S); } }
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.

-- Frag.

Replies are listed 'Best First'.
Re (tilly) 2: dying() more informatively
by tilly (Archbishop) on May 09, 2001 at 12:08 UTC
    If you read the question closely, what the person wants is a call-stack. The die is happening from read_file. But that information is useless because everything has to read files. What you really want to know is where you were 2 calls back, in parse_template. For that you really wanted to use Carp's confess.
Re: Re: dying() more informatively
by premchai21 (Curate) on May 09, 2001 at 06:45 UTC
    I think you're a bit mixed up here. croak() calls die() and carp() calls warn(), not vice versa.
Re: Re: dying() more informatively
by novitiate (Scribe) on May 09, 2001 at 05:22 UTC
    This looks better than the first two suggestions;
    alternatively, you can replace the CORE::die function with
    your own; to start see:

    Bekman, Stas. mod_perl guide, chapter 3.12

    humbly,
    novitiate