{
    "mode": "perldoc",
    "parameter": "if",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/if/json",
    "generated": "2026-06-12T02:58:50Z",
    "synopsis": "use if CONDITION, \"MODULE\", ARGUMENTS;\nno  if CONDITION, \"MODULE\", ARGUMENTS;",
    "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": "\"use if\"\nThe \"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 above\nline 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 compile\ntime, with:\n\nBEGIN { require MODULE if CONDITION }\n\n\"no if\"\nThe \"no if\" construct is mainly used to deactivate categories of warnings when those categories\nwould 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 was\nrunning warnings-free on earlier versions of perl and you don't care about \"redundant\" warnings\nin 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 \"unimport()\"\nmethod -- but most modules and pragmata have not. That explains why the \"no if\" construct is of\nlimited applicability.\n",
            "subsections": []
        },
        "BUGS": {
            "content": "The current implementation does not allow specification of the required version of the module.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "Module::Requires can be used to conditionally load one or modules, with constraints based on the\nversion 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 are\navailable, 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 based\non 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 Perl\n5 programming language system itself.\n",
            "subsections": []
        }
    },
    "summary": "if - \"use\" a Perl module if a condition holds",
    "flags": [],
    "examples": [],
    "see_also": []
}