Search code examples
perlwarningsundef

How can you get Perl to stop when referencing an undef value?


How do you get Perl to stop and give a stack trace when you reference an undef value, rather than merely warning? It seems that use strict; isn't sufficient for this purpose.


Solution

  • use warnings FATAL => 'uninitialized';
    
    use Carp ();
    $SIG{__DIE__} = \&Carp::confess;
    

    The first line makes the warning fatal. The next two cause a stack trace when your program dies.

    See also man 3pm warnings for more details.