There are (currently) three options for "strictness". Though you should usually use all three by placing:

use strict;
near the top of each of your Perl files. This will help to make your source code easier to maintain.

use strict "vars"

If you use strict "vars", then you will get an error if you ever use a variable without "declaring" it. You can "declare" a variable via:

Detection of undeclared variables happens at compile time.

use strict "subs"

If you use strict "subs", then you will get an error for most uses of "barewords". Without this strictness, Perl will often interpret an unadorned identifier as a string:

print " ", Hello, ", ", World::ALL, "!\n"; # prints " Hello, World::ALL!"

It is good to use this strictness because forgetting to "adorn" an identifier is a common mistake. Perhaps you meant to write:

print " ", Hello(), ", ", $World::ALL, "!\n";

There are lots of ways to adorn an identifier so that it won't be a bareword:

And there are several ways you are expected to use barewords that will not be complained about even if you use strict "subs":

Detection of barewords happens at compile time. This is particularly nice because you can make a policy of making sure many of your subroutines are declared before you use them (especially in the case of constants which are usually imported from modules) and them call them as barewords (no parens and no &) and then Perl will detect typos in these names at compile time for you.

use strict "refs"

If you use strict "refs", then you will get an error if you try to access a variable by "computing" its name. This is called a symbolic reference. For example:

use vars qw( $this $that ); my $varname= @ARGV ? "this" : "that"; ${$varname}= "In use"; # This line uses a symbolic reference.

Symbolic references were often used in Perl4. Perl5 has real references (often created with the backslash operator, \) that should be used instead (or perhaps you should be using a hash and computing key names instead of computing variable names). Perl5 also has lexical variables (see the my operator) that can't be accessed via symbolic references. Catching symbolic reference is good because a common mistake is having a variable that should contain a real reference but doesn't. Dereferencing such a variable might silently fetch you garbage without this strictness.

Detection of using symbolic references happens at run time.

If you have one of those truely rare cases where you need to do symbolic references in Perl5, then you can delcare no strict "refs" for just that chunk of code or use eval.

Updated to cover a few more cases.

        - tye (but my friends call me "Tye")

In reply to strict.pm by tye

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.