Instead generate a core dump or something similar, I would recommended you log messages in your script and do some checks specially when you are trying to access something that does not exists.
Using a source level debugger as suggested in perldoc are for some rare cases:
If the debugging output of -D doesn't help you, it's time to step
through perl's execution with a source-level debugger.
We'll use gdb for our examples here; the principles will apply to
any debugger (many vendors call their debugger dbx ), but check the
manual of the one you're using.
Trying to access a position of an array that does not exists can be avoided by using if
and else
for example:
my $wanted_position = 2;
if ( $wanted_position >= @array )
{
#log a possible error
#Do something else
}
@a = @{$array[$wanted_position]};
You can handle signals inside your script also.
Perl uses a simple signal handling model: the %SIG hash contains names
or references of user-installed signal handlers. These handlers will
be called with an argument which is the name of the signal that
triggered it. A signal may be generated intentionally from a
particular keyboard sequence like control-C or control-Z, sent to you
from another process, or triggered automatically by the kernel when
special events transpire, like a child process exiting, your own
process running out of stack space, or hitting a process file-size
limit.
Example:
$SIG{DIE} = sub { #dump code here };