{
    "content": [
        {
            "type": "text",
            "text": "# if (man)\n\n## NAME\n\nif - \"use\" a Perl module if a condition holds\n\n## SYNOPSIS\n\nuse if CONDITION, \"MODULE\", ARGUMENTS;\nno  if CONDITION, \"MODULE\", ARGUMENTS;\n\n## TLDR\n\n> Perform conditional processing in shell scripts.\n\n- Execute the specified commands if the condition command's exit status is zero:\n  `if {{condition_command}}; then {{echo \"Condition is true\"}}; fi`\n- Execute the specified commands if the condition command's exit status is not zero:\n  `if ! {{condition_command}}; then {{echo \"Condition is true\"}}; fi`\n- Execute the first specified commands if the condition command's exit status is zero otherwise execute the second specified commands:\n  `if {{condition_command}}; then {{echo \"Condition is true\"}}; else {{echo \"Condition is false\"}}; fi`\n- Check whether a [f]ile exists:\n  `if [[ -f {{path/to/file}} ]]; then {{echo \"Condition is true\"}}; fi`\n- Check whether a [d]irectory exists:\n  `if [[ -d {{path/to/directory}} ]]; then {{echo \"Condition is true\"}}; fi`\n- Check whether a file or directory [e]xists:\n  `if [[ -e {{path/to/file_or_directory}} ]]; then {{echo \"Condition is true\"}}; fi`\n- Check whether a variable is defined:\n  `if [[ -n \"${{variable}}\" ]]; then {{echo \"Condition is true\"}}; fi`\n- List all possible conditions (`test` is an alias to `[`; both are commonly used with `if`):\n  `man test`\n\n*Source: tldr-pages*\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION** (2 subsections)\n- **BUGS**\n- **SEE ALSO**\n- **AUTHOR**\n- **COPYRIGHT AND LICENCE**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "if",
        "section": "",
        "mode": "man",
        "summary": "if - \"use\" a Perl module if a condition holds",
        "synopsis": "use if CONDITION, \"MODULE\", ARGUMENTS;\nno  if CONDITION, \"MODULE\", ARGUMENTS;",
        "tldr_summary": "Perform conditional processing in shell scripts.",
        "tldr_examples": [
            {
                "description": "Execute the specified commands if the condition command's exit status is zero",
                "command": "if {{condition_command}}; then {{echo \"Condition is true\"}}; fi"
            },
            {
                "description": "Execute the specified commands if the condition command's exit status is not zero",
                "command": "if ! {{condition_command}}; then {{echo \"Condition is true\"}}; fi"
            },
            {
                "description": "Execute the first specified commands if the condition command's exit status is zero otherwise execute the second specified commands",
                "command": "if {{condition_command}}; then {{echo \"Condition is true\"}}; else {{echo \"Condition is false\"}}; fi"
            },
            {
                "description": "Check whether a [f]ile exists",
                "command": "if [[ -f {{path/to/file}} ]]; then {{echo \"Condition is true\"}}; fi"
            },
            {
                "description": "Check whether a [d]irectory exists",
                "command": "if [[ -d {{path/to/directory}} ]]; then {{echo \"Condition is true\"}}; fi"
            },
            {
                "description": "Check whether a file or directory [e]xists",
                "command": "if [[ -e {{path/to/file_or_directory}} ]]; then {{echo \"Condition is true\"}}; fi"
            },
            {
                "description": "Check whether a variable is defined",
                "command": "if [[ -n \"${{variable}}\" ]]; then {{echo \"Condition is true\"}}; fi"
            },
            {
                "description": "List all possible conditions (`test` is an alias to `[`; both are commonly used with `if`)",
                "command": "man test"
            }
        ],
        "tldr_source": "official",
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 1,
                "subsections": [
                    {
                        "name": "\"use if\"",
                        "lines": 26
                    },
                    {
                        "name": "\"no if\"",
                        "lines": 18
                    }
                ]
            },
            {
                "name": "BUGS",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 9,
                "subsections": []
            },
            {
                "name": "AUTHOR",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "COPYRIGHT AND LICENCE",
                "lines": 8,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "if - \"use\" a Perl module if a condition holds\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "use if CONDITION, \"MODULE\", ARGUMENTS;\nno  if CONDITION, \"MODULE\", ARGUMENTS;\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "",
                "subsections": [
                    {
                        "name": "\"use if\"",
                        "content": "The \"if\" module is used to conditionally load another module.  The construct:\n\nuse if CONDITION, \"MODULE\", ARGUMENTS;\n\n... will load \"MODULE\" only if \"CONDITION\" evaluates to true; it has no effect if \"CONDITION\"\nevaluates to false.  (The module name, assuming it contains at least one \"::\", must be quoted\nwhen 'use strict \"subs\";' is in effect.)  If the CONDITION does evaluate to true, then the\nabove line has the same effect as:\n\nuse MODULE ARGUMENTS;\n\nFor example, the Unicode::UCD module's charinfo function will use two functions from\nUnicode::Normalize only if a certain condition is met:\n\nuse if defined &DynaLoader::bootDynaLoader,\n\"Unicode::Normalize\" => qw(getCombinClass NFD);\n\nSuppose you wanted \"ARGUMENTS\" to be an empty list, i.e., to have the effect of:\n\nuse MODULE ();\n\nYou can't do this with the \"if\" pragma; however, you can achieve exactly this effect, at\ncompile time, with:\n\nBEGIN { require MODULE if CONDITION }\n"
                    },
                    {
                        "name": "\"no if\"",
                        "content": "The \"no if\" construct is mainly used to deactivate categories of warnings when those\ncategories would produce superfluous output under specified versions of perl.\n\nFor example, the \"redundant\" category of warnings was introduced in Perl-5.22.  This warning\nflags certain instances of superfluous arguments to \"printf\" and \"sprintf\".  But if your code\nwas running warnings-free on earlier versions of perl and you don't care about \"redundant\"\nwarnings in more recent versions, you can call:\n\nuse warnings;\nno if $] >= 5.022, q|warnings|, qw(redundant);\n\nmy $test    = { fmt  => \"%s\", args => [ qw( x y ) ] };\nmy $result  = sprintf $test->{fmt}, @{$test->{args}};\n\nThe \"no if\" construct assumes that a module or pragma has correctly implemented an\n\"unimport()\" method -- but most modules and pragmata have not.  That explains why the \"no if\"\nconstruct is of limited applicability.\n"
                    }
                ]
            },
            "BUGS": {
                "content": "The current implementation does not allow specification of the required version of the\nmodule.\n",
                "subsections": []
            },
            "SEE ALSO": {
                "content": "Module::Requires can be used to conditionally load one or modules, with constraints based on\nthe version of the module.  Unlike \"if\" though, Module::Requires is not a core module.\n\nModule::Load::Conditional provides a number of functions you can use to query what modules\nare available, and then load one or more of them at runtime.\n\nThe provide module from CPAN can be used to select one of several possible modules to load\nbased on the version of Perl that is running.\n",
                "subsections": []
            },
            "AUTHOR": {
                "content": "Ilya Zakharevich <mailto:ilyaz@cpan.org>.\n",
                "subsections": []
            },
            "COPYRIGHT AND LICENCE": {
                "content": "This software is copyright (c) 2002 by Ilya Zakharevich.\n\nThis is free software; you can redistribute it and/or modify it under the same terms as the\nPerl 5 programming language system itself.\n\n\n\nperl v5.34.0                                 2025-07-25                                    if(3perl)",
                "subsections": []
            }
        }
    }
}