{
    "content": [
        {
            "type": "text",
            "text": "# diagnostics (man)\n\n## NAME\n\ndiagnostics, splain - produce verbose warning diagnostics\n\n## SYNOPSIS\n\nUsing the \"diagnostics\" pragma:\nuse diagnostics;\nuse diagnostics -verbose;\nenable  diagnostics;\ndisable diagnostics;\nUsing the \"splain\" standalone filter program:\nperl program 2>diag.out\nsplain [-v] [-p] diag.out\nUsing diagnostics to get stack traces from a misbehaving script:\nperl -Mdiagnostics=-traceonly myscript.pl\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION** (1 subsections)\n- **EXAMPLES**\n- **INTERNALS**\n- **BUGS**\n- **AUTHOR**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "diagnostics",
        "section": "",
        "mode": "man",
        "summary": "diagnostics, splain - produce verbose warning diagnostics",
        "synopsis": "Using the \"diagnostics\" pragma:\nuse diagnostics;\nuse diagnostics -verbose;\nenable  diagnostics;\ndisable diagnostics;\nUsing the \"splain\" standalone filter program:\nperl program 2>diag.out\nsplain [-v] [-p] diag.out\nUsing diagnostics to get stack traces from a misbehaving script:\nperl -Mdiagnostics=-traceonly myscript.pl",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [
            "The following file is certain to trigger a few errors at both runtime and compiletime:",
            "use diagnostics;",
            "print NOWHERE \"nothing\\n\";",
            "print STDERR \"\\n\\tThis message should be unadorned.\\n\";",
            "warn \"\\tThis is a user warning\";",
            "print \"\\nDIAGNOSTIC TESTER: Please enter a <CR> here: \";",
            "my $a, $b = scalar <STDIN>;",
            "print \"\\n\";",
            "print $x/$y;",
            "If you prefer to run your program first and look at its problem afterwards, do this:",
            "perl -w test.pl 2>test.out",
            "./splain < test.out",
            "Note that this is not in general possible in shells of more dubious heritage, as the",
            "theoretical",
            "(perl -w test.pl >/dev/tty) >& test.out",
            "./splain < test.out",
            "Because you just moved the existing stdout to somewhere else.",
            "If you don't want to modify your source code, but still have on-the-fly warnings, do this:",
            "exec 3>&1; perl -w test.pl 2>&1 1>&3 3>&- | splain 1>&2 3>&-",
            "Nifty, eh?",
            "If you want to control warnings on the fly, do something like this.  Make sure you do the",
            "\"use\" first, or you won't be able to get at the enable() or disable() methods.",
            "use diagnostics; # checks entire compilation phase",
            "print \"\\ntime for 1st bogus diags: SQUAWKINGS\\n\";",
            "print BOGUS1 'nada';",
            "print \"done with 1st bogus\\n\";",
            "disable diagnostics; # only turns off runtime warnings",
            "print \"\\ntime for 2nd bogus: (squelched)\\n\";",
            "print BOGUS2 'nada';",
            "print \"done with 2nd bogus\\n\";",
            "enable diagnostics; # turns back on runtime warnings",
            "print \"\\ntime for 3rd bogus: SQUAWKINGS\\n\";",
            "print BOGUS3 'nada';",
            "print \"done with 3rd bogus\\n\";",
            "disable diagnostics;",
            "print \"\\ntime for 4th bogus: (squelched)\\n\";",
            "print BOGUS4 'nada';",
            "print \"done with 4th bogus\\n\";"
        ],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 17,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 1,
                "subsections": [
                    {
                        "name": "The \"diagnostics\" Pragma",
                        "lines": 44
                    }
                ]
            },
            {
                "name": "EXAMPLES",
                "lines": 53,
                "subsections": []
            },
            {
                "name": "INTERNALS",
                "lines": 13,
                "subsections": []
            },
            {
                "name": "BUGS",
                "lines": 13,
                "subsections": []
            },
            {
                "name": "AUTHOR",
                "lines": 5,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "diagnostics, splain - produce verbose warning diagnostics\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "Using the \"diagnostics\" pragma:\n\nuse diagnostics;\nuse diagnostics -verbose;\n\nenable  diagnostics;\ndisable diagnostics;\n\nUsing the \"splain\" standalone filter program:\n\nperl program 2>diag.out\nsplain [-v] [-p] diag.out\n\nUsing diagnostics to get stack traces from a misbehaving script:\n\nperl -Mdiagnostics=-traceonly myscript.pl\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "",
                "subsections": [
                    {
                        "name": "The \"diagnostics\" Pragma",
                        "content": "This module extends the terse diagnostics normally emitted by both the perl compiler and the\nperl interpreter (from running perl with a -w switch or \"use warnings\"), augmenting them with\nthe more explicative and endearing descriptions found in perldiag.  Like the other pragmata,\nit affects the compilation phase of your program rather than merely the execution phase.\n\nTo use in your program as a pragma, merely invoke\n\nuse diagnostics;\n\nat the start (or near the start) of your program.  (Note that this does enable perl's -w\nflag.)  Your whole compilation will then be subject(ed :-) to the enhanced diagnostics.\nThese still go out STDERR.\n\nDue to the interaction between runtime and compiletime issues, and because it's probably not\na very good idea anyway, you may not use \"no diagnostics\" to turn them off at compiletime.\nHowever, you may control their behaviour at runtime using the disable() and enable() methods\nto turn them off and on respectively.\n\nThe -verbose flag first prints out the perldiag introduction before any other diagnostics.\nThe $diagnostics::PRETTY variable can generate nicer escape sequences for pagers.\n\nWarnings dispatched from perl itself (or more accurately, those that match descriptions found\nin perldiag) are only displayed once (no duplicate descriptions).  User code generated\nwarnings a la warn() are unaffected, allowing duplicate user messages to be displayed.\n\nThis module also adds a stack trace to the error message when perl dies.  This is useful for\npinpointing what caused the death.  The -traceonly (or just -t) flag turns off the\nexplanations of warning messages leaving just the stack traces.  So if your script is dieing,\nrun it again with\n\nperl -Mdiagnostics=-traceonly mybadscript\n\nto see the call stack at the time of death.  By supplying the -warntrace (or just -w) flag,\nany warnings emitted will also come with a stack trace.\n\nThe splain Program\nWhile apparently a whole nuther program, splain is actually nothing more than a link to the\n(executable) diagnostics.pm module, as well as a link to the diagnostics.pod documentation.\nThe -v flag is like the \"use diagnostics -verbose\" directive.  The -p flag is like the\n$diagnostics::PRETTY variable.  Since you're post-processing with splain, there's no sense in\nbeing able to enable() or disable() processing.\n\nOutput from splain is directed to STDOUT, unlike the pragma.\n"
                    }
                ]
            },
            "EXAMPLES": {
                "content": "The following file is certain to trigger a few errors at both runtime and compiletime:\n\nuse diagnostics;\nprint NOWHERE \"nothing\\n\";\nprint STDERR \"\\n\\tThis message should be unadorned.\\n\";\nwarn \"\\tThis is a user warning\";\nprint \"\\nDIAGNOSTIC TESTER: Please enter a <CR> here: \";\nmy $a, $b = scalar <STDIN>;\nprint \"\\n\";\nprint $x/$y;\n\nIf you prefer to run your program first and look at its problem afterwards, do this:\n\nperl -w test.pl 2>test.out\n./splain < test.out\n\nNote that this is not in general possible in shells of more dubious heritage, as the\ntheoretical\n\n(perl -w test.pl >/dev/tty) >& test.out\n./splain < test.out\n\nBecause you just moved the existing stdout to somewhere else.\n\nIf you don't want to modify your source code, but still have on-the-fly warnings, do this:\n\nexec 3>&1; perl -w test.pl 2>&1 1>&3 3>&- | splain 1>&2 3>&-\n\nNifty, eh?\n\nIf you want to control warnings on the fly, do something like this.  Make sure you do the\n\"use\" first, or you won't be able to get at the enable() or disable() methods.\n\nuse diagnostics; # checks entire compilation phase\nprint \"\\ntime for 1st bogus diags: SQUAWKINGS\\n\";\nprint BOGUS1 'nada';\nprint \"done with 1st bogus\\n\";\n\ndisable diagnostics; # only turns off runtime warnings\nprint \"\\ntime for 2nd bogus: (squelched)\\n\";\nprint BOGUS2 'nada';\nprint \"done with 2nd bogus\\n\";\n\nenable diagnostics; # turns back on runtime warnings\nprint \"\\ntime for 3rd bogus: SQUAWKINGS\\n\";\nprint BOGUS3 'nada';\nprint \"done with 3rd bogus\\n\";\n\ndisable diagnostics;\nprint \"\\ntime for 4th bogus: (squelched)\\n\";\nprint BOGUS4 'nada';\nprint \"done with 4th bogus\\n\";\n",
                "subsections": []
            },
            "INTERNALS": {
                "content": "Diagnostic messages derive from the perldiag.pod file when available at runtime.  Otherwise,\nthey may be embedded in the file itself when the splain package is built.   See the Makefile\nfor details.\n\nIf an extant $SIG{WARN} handler is discovered, it will continue to be honored, but only\nafter the diagnostics::splainthis() function (the module's $SIG{WARN} interceptor) has\nhad its way with your warnings.\n\nThere is a $diagnostics::DEBUG variable you may set if you're desperately curious what sorts\nof things are being intercepted.\n\nBEGIN { $diagnostics::DEBUG = 1 }\n",
                "subsections": []
            },
            "BUGS": {
                "content": "Not being able to say \"no diagnostics\" is annoying, but may not be insurmountable.\n\nThe \"-pretty\" directive is called too late to affect matters.  You have to do this instead,\nand before you load the module.\n\nBEGIN { $diagnostics::PRETTY = 1 }\n\nI could start up faster by delaying compilation until it should be needed, but this gets a\n\"panic: toplevel\" when using the pragma form in Perl 5.001e.\n\nWhile it's true that this documentation is somewhat subserious, if you use a program named\nsplain, you should expect a bit of whimsy.\n",
                "subsections": []
            },
            "AUTHOR": {
                "content": "Tom Christiansen <tchrist@mox.perl.com>, 25 June 1995.\n\n\n\nperl v5.34.0                                 2025-07-25                                    SPLAIN(1)",
                "subsections": []
            }
        }
    }
}