|Home » Faqs » Perl thinking » Warnings|
Sometimes at the top of a Perl program you'll see:
and sometimes you'll see:
When you add
-w you're asking the Perl compiler to warn you about things in
your code that may be errors.
The following rather sloppy little program assumes that
#!/usr/bin/perl print "Today is $day\n"; exit 0;
and it produces the following output:
However with the addition of the -w command line flag:
#!/usr/bin/perl -w print "Today is $day\n"; exit 0;
when we run the program we are duly warned:
Name "main::day" used only once: possible typo at ./t.pl line 5. Use of uninitialized value in concatenation (.) or string at ./t.pl line 5. Today is
These days, the
-w command line flag is usually replaced with the
warnings pragma, as the latter is more flexible, and has scope that is
limited to the enclosing block, whilst
-w is global in effect.
You'll find that the combination of the
will catch lots of errors before they get out of hand.
So make a point of starting any program with:
#!/usr/bin/perl use strict; use warnings;
perldoc perlrun (look for -w) perldoc perllexwarn perldoc warnings perldoc diagnostics perldoc perldiag