{
    "mode": "perldoc",
    "parameter": "strict",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/strict/json",
    "generated": "2026-06-11T05:38:37Z",
    "synopsis": "use strict;\nuse strict \"vars\";\nuse strict \"refs\";\nuse strict \"subs\";\nuse strict;\nno strict \"vars\";",
    "sections": {
        "NAME": {
            "content": "strict - Perl pragma to restrict unsafe constructs\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use strict;\n\nuse strict \"vars\";\nuse strict \"refs\";\nuse strict \"subs\";\n\nuse strict;\nno strict \"vars\";\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "The \"strict\" pragma disables certain Perl expressions that could behave unexpectedly or are\ndifficult to debug, turning them into errors. The effect of this pragma is limited to the\ncurrent file or scope block.\n\nIf no import list is supplied, all possible restrictions are assumed. (This is the safest mode\nto operate in, but is sometimes too strict for casual programming.) Currently, there are three\npossible things to be strict about: \"subs\", \"vars\", and \"refs\".\n\n\"strict refs\"\nThis generates a runtime error if you use symbolic references (see perlref).\n\nuse strict 'refs';\n$ref = \\$foo;\nprint $$ref;        # ok\n$ref = \"foo\";\nprint $$ref;        # runtime error; normally ok\n$file = \"STDOUT\";\nprint $file \"Hi!\";  # error; note: no comma after $file\n\nThere is one exception to this rule:\n\n$bar = \\&{'foo'};\n&$bar;\n\nis allowed so that \"goto &$AUTOLOAD\" would not break under stricture.\n\n\"strict vars\"\nThis generates a compile-time error if you access a variable that was neither explicitly\ndeclared (using any of \"my\", \"our\", \"state\", or \"use vars\") nor fully qualified. (Because\nthis is to avoid variable suicide problems and subtle dynamic scoping issues, a merely\n\"local\" variable isn't good enough.) See \"my\" in perlfunc, \"our\" in perlfunc, \"state\" in\nperlfunc, \"local\" in perlfunc, and vars.\n\nuse strict 'vars';\n$X::foo = 1;         # ok, fully qualified\nmy $foo = 10;        # ok, my() var\nlocal $baz = 9;      # blows up, $baz not declared before\n\npackage Cinna;\nour $bar;                   # Declares $bar in current package\n$bar = 'HgS';               # ok, global declared via pragma\n\nThe local() generated a compile-time error because you just touched a global name without\nfully qualifying it.\n\nBecause of their special use by sort(), the variables $a and $b are exempted from this\ncheck.\n\n\"strict subs\"\nThis disables the poetry optimization, generating a compile-time error if you try to use a\nbareword identifier that's not a subroutine, unless it is a simple identifier (no colons)\nand that it appears in curly braces, on the left hand side of the \"=>\" symbol, or has the\nunary minus operator applied to it.\n\nuse strict 'subs';\n$SIG{PIPE} = Plumber;   # blows up\n$SIG{PIPE} = \"Plumber\"; # fine: quoted string is always ok\n$SIG{PIPE} = \\&Plumber; # preferred form\n\nSee \"Pragmatic Modules\" in perlmodlib.\n",
            "subsections": []
        },
        "HISTORY": {
            "content": "\"strict 'subs'\", with Perl 5.6.1, erroneously permitted to use an unquoted compound identifier\n(e.g. \"Foo::Bar\") as a hash key (before \"=>\" or inside curlies), but without forcing it always\nto a literal string.\n\nStarting with Perl 5.8.1 strict is strict about its restrictions: if unknown restrictions are\nused, the strict pragma will abort with\n\nUnknown 'strict' tag(s) '...'\n\nAs of version 1.04 (Perl 5.10), strict verifies that it is used as \"strict\" to avoid the dreaded\nStrict trap on case insensitive file systems.\n",
            "subsections": []
        }
    },
    "summary": "strict - Perl pragma to restrict unsafe constructs",
    "flags": [],
    "examples": [],
    "see_also": []
}