Perl pragma introduced in Perl 5.6 or so, to more or less replace the previously introduced -w command line switch.

The warnings pragma is used very much like strict pragma. Typically, you want to start the program like this, to avoid embarassing questions from Python zealots:

#!/usr/bin/perl

use warnings;
use strict;

This will enable all warnings and only use proper style.

Warnings pragma is much more flexible than -w. You can disable warnings temporarily inside blocks with no warnings; (certainly more readable than local($^W)=0; and also works in compile phase!), and you can enable specific warnings with things like use warnings qw(syntax utf8);. Also, you can make warnings fatal: use warnings FATAL => qw(syntax); And that's not all! You can also make your own enablable/disablable warnings with it, using the stuff in warnings::register package...

Plain use warnings; is equivalent to use warnings 'all';.

Here's a list of all warning categories, taken from perllexwarn perldoc of Perl 5.6.1:

  • all
    • chmod
    • closure
    • exiting
    • glob
    • io
      • closed
      • exec
      • newline
      • pipe
      • unopened
    • misc
    • numeric
    • once
    • overflow
    • pack
    • portable
    • recursion
    • redefine
    • regexp
    • severe
      • debugging
      • inplace
      • internal
      • malloc
    • signal
    • substr
    • syntax
      • ambiguous
      • bareword
      • deprecated
      • digit
      • parenthesis
      • precedence
      • printf
      • prototype
      • qw
      • reserved
      • semicolon
    • taint
    • umask
    • uninitialized
    • unpack
    • untie
    • utf8
    • void
    • y2k

Log in or register to write something here or to contact authors.