strict(3perl)

πŸ‘‘ strict β€” the Perl pragma that said "no ❀️, we're being careful now" πŸ’…

okay bestie, buckle up. this is strict(3perl) from the Perl Programmers Reference Guide, and it's genuinely one of the most iconic little pragmas in the whole Perl universe. it's the friend who texts you "girl don't do that" right before you do the thing. 🫢


✨ NAME ✨

strict β€” the Perl pragma that restricts unsafe constructs. she's a vibe check for your code. 🌸


✨ SYNOPSIS ✨

    use strict;

    use strict "vars";
    use strict "refs";
    use strict "subs";

    use strict;
    no strict "vars";

like... that's it. that's the whole incantation. throw use strict; at the top of your file and suddenly Perl is your mom watching you do homework. 😭


✨ DESCRIPTION ✨

so the tea is: the strict pragma disables certain Perl expressions that could behave unexpectedly or are genuinely a nightmare to debug, and it turns them into errors instead. iconic behavior honestly. πŸ’…

important though β€” the effect of this pragma is limited to the current file or scope block. so it's not a global curse, it's a localized one. very demure, very mindful.

if you don't give it an import list at all, all possible restrictions are assumed. that's the safest mode to operate in, but ngl it's sometimes too strict for casual programming. (casual programming is exactly the vibe that needs her most tho πŸ™ˆ)

currently there are three possible things to be strict about: "subs", "vars", and "refs". three little gremlins. let's meet them.

🌈 "strict refs" 🌈

this one generates a runtime error if you use symbolic references (peep perlref for the lore). no cap, she will simply not allow it.

    use strict 'refs';
    $ref = \$foo;
    print $$ref;        # ok
    $ref = "foo";
    print $$ref;        # runtime error; normally ok
    $file = "STDOUT";
    print $file "Hi!";  # error; note: no comma after $file

but wait, there's one exception to this rule, and it's a sweet one:

    $bar = \&{'foo'};
    &$bar;

that's allowed, and the whole reason is so that goto &$AUTOLOAD wouldn't break under stricture. we love a protective queen. πŸ‘‘

🌈 "strict vars" 🌈

this one generates a compile-time error if you access a variable that was neither explicitly declared (using any of my, our, state, or use vars) nor fully qualified. πŸ’€

and before you come for her β€” because this is to avoid variable suicide problems and subtle dynamic scoping issues, a merely local variable isn't good enough. sorry babe.

see "my" in perlfunc, "our" in perlfunc, "state" in perlfunc, "local" in perlfunc, and vars for the full receipts.

    use strict 'vars';
    $X::foo = 1;         # ok, fully qualified
    my $foo = 10;        # ok, my() var
    local $baz = 9;      # blows up, $baz not declared before

    package Cinna;
    our $bar;                   # Declares $bar in current package
    $bar = 'HgS';               # ok, global declared via pragma

so the local() line generated a compile-time error because you just touched a global name without fully qualifying it. the audacity. the disrespect. 😭

because of their special use by sort(), the variables $a and $b are exempted from this check. they're the exceptions that got a hall pass fr fr. πŸŽ€

🌈 "strict subs" 🌈

this one disables the poetry optimization, generating a compile-time error if you try to use a bareword identifier that's not a subroutine β€” unless it is a simple identifier (no colons) and that it appears in curly braces, on the left hand side of the => symbol, or has the unary minus operator applied to it. yes that's a lot of conditions, she has standards. πŸ’…

    use strict 'subs';
    $SIG{PIPE} = Plumber;   # blows up
    $SIG{PIPE} = "Plumber"; # fine: quoted string is always ok
    $SIG{PIPE} = \&Plumber; # preferred form

look at that glow-up. from Plumber (blows up πŸ’€) to \&Plumber (the preferred form ✨).


also, go read "Pragmatic Modules" in perlmodlib. it's giving syllabus energy. πŸ“š


✨ HISTORY ✨

storytime bestie, sit down. πŸ“

"strict 'subs'", with Perl 5.6.1, erroneously permitted to use an unquoted compound identifier (e.g. "Foo::Bar") as a hash key (before => or inside curlies), but without forcing it always to a literal string. a little oopsie. we don't talk about it. πŸ™ˆ

starting with Perl 5.8.1, strict is strict about its restrictions: if unknown restrictions are used, the strict pragma will abort with

    Unknown 'strict' tag(s) '...'

as of version 1.04 (Perl 5.10), strict verifies that it is used as "strict" to avoid the dreaded Strict trap on case insensitive file systems. (case insensitive file systems stay causing chaos, it's giving Windows energy πŸ’€)

beginning with Perl 5.12, use of "use VERSION" (where VERSION >= 5.11.0) now lexically enables strictures just like "use strict" (in addition to the normal "use VERSION" effects and features.) in other words, "use v5.011" or higher now implies "use strict" automatically, as noted in "Implicit strictures" in perl5120delta and "use VERSION". she just does it for you now. self-care. 🌸


πŸ’– and that's the whole page, bestie. this was strict(3perl) from perl v5.44.0, dated 2026-10-17. slay, protect your scope, and always use strict;. periodt. πŸ‘‘βœ¨πŸŽ€
πŸ“¦ where this page comes from
  • arch rolling: perl 5.44.0-1 Β· Artistic-1.0-Perl AND GPL-1.0-or-later
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms