Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

cause perl to die on use of unintialized variables

by david2008 (Scribe)
on Jun 23, 2010 at 11:12 UTC ( #846050=perlquestion: print w/replies, xml ) Need Help??
david2008 has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,

I want perl in the development phase to be stricter and die on use of uninitialized variables.
I did not find something with googling.
Is there a possibility to make this ?

  • Comment on cause perl to die on use of unintialized variables

Replies are listed 'Best First'.
Re: cause perl to die on use of unintialized variables
by moritz (Cardinal) on Jun 23, 2010 at 11:22 UTC
    use warnings FATAL => qw(uninitialized);

    should do what you want.

    Update: if you don't want to add that to your file, but rather want it confined to development uses only, you can also run your perl script as

    $ perl -Mwarnings=FATAL,uninitialized

    to get that effect without modifying your script. But beware, it can be overridden inside the script, or in modules used by the script.

    For more information on the warnings pragma, please consult perllexwarn.

    Perl 6 - links to (nearly) everything that is Perl 6.
Re: cause perl to die on use of unintialized variables
by chromatic (Archbishop) on Jun 23, 2010 at 11:26 UTC

    The warnings pragma has a FATAL option:

    use warnings FATAL => 'uninitialized';

    This has a lexical scope, so you have to enable it in every scope in which you want it to take effect. See perllexwarn. Alternately you can set up your own global warn handler by sticking a code ref in $SIG{__WARN__}, but that's uglier.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://846050]
Approved by Corion
Front-paged by Corion
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2018-01-23 22:15 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (254 votes). Check out past polls.