Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
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

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 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?
[1nickt]: kgb not quite as simple as ... and ...; are interchangeable. There are edge cases, shown in perlsyn.
[1nickt]: Hm well actually I guess it's not the trailing semi-colon that's at issue there, it's disambiguation between the ellipsis and the binary flip-flop
[1nickt]: Although the example given does not produce an error as stated, on my perl.

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (10)
As of 2017-11-18 19:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (277 votes). Check out past polls.

    Notices?