in reply to How do I get a post mortem stack trace?

you could do something like putting an eval() statement around your entire script, which is easily accomplished by the following:
# beginning of program eval { main(); }; if ( $@ ) { confess(); } sub main { ... }
Here, just make the sub main() be what would normally be the program block outside of any function call, i.e. heres how to turn hello world into what i'm saying
#!/usr/bin/perl -w use strict; use Carp; eval { main(); }; if ( $@ ) { confess(); } exit; sub main { print "hello world\n"; }
Trivial example, this should never die, if it does, you have bigger problems.

Replies are listed 'Best First'.
Re: Re: How do I get a post mortem stack trace?
by rinceWind (Monsignor) on Nov 11, 2002 at 16:31 UTC
    No cigar.
    #!/usr/bin/perl -w use strict; use Carp; eval { main(); }; if ( $@ ) { confess($@); } exit; sub foo { my $aargh = shift; die $aargh; } sub main { foo "hello world\n"; }
    I don't get a stack trace. Once it has finished the eval, the stack is no longer there.