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

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 ?

Thanks,
David

Comment on cause perl to die on use of unintialized variables
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 filename.pl

    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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://846050]
Approved by Corion
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (10)
As of 2014-11-24 12:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (141 votes), past polls