1if(3pm) Perl Programmers Reference Guide if(3pm)
2
3
4
6 if - "use" a Perl module if a condition holds (also can "no" a module)
7
9 use if CONDITION, MODULE => ARGUMENTS;
10 no if CONDITION, MODULE => ARGUMENTS;
11
13 The "if" module is used to conditionally load or unload another module.
14 The construct
15
16 use if CONDITION, MODULE => ARGUMENTS;
17
18 will load MODULE only if CONDITION evaluates to true. The above
19 statement has no effect unless "CONDITION" is true. If the CONDITION
20 does evaluate to true, then the above line has the same effect as:
21
22 use MODULE ARGUMENTS;
23
24 The use of "=>" above provides necessary quoting of "MODULE". If you
25 don't use the fat comma (eg you don't have any ARGUMENTS), then you'll
26 need to quote the MODULE.
27
28 EXAMPLES
29 The following line is taken from the testsuite for File::Map:
30
31 use if $^O ne 'MSWin32', POSIX => qw/setlocale LC_ALL/;
32
33 If run on any operating system other than Windows, this will import the
34 functions "setlocale" and "LC_ALL" from POSIX. On Windows it does
35 nothing.
36
37 The following is used to deprecate core modules beyond a certain
38 version of Perl:
39
40 use if $] > 5.016, 'deprecate';
41
42 This line is taken from Text::Soundex 3.04, and marks it as deprecated
43 beyond Perl 5.16. If you "use Text::Soundex" in Perl 5.18, for
44 example, and you have used warnings, then you'll get a warning message
45 (the deprecate module looks to see whether the calling module was
46 "use"'d from a core library directory, and if so, generates a warning),
47 unless you've installed a more recent version of Text::Soundex from
48 CPAN.
49
50 You can also specify to NOT use something:
51
52 no if $] ge 5.021_006, warnings => "locale";
53
54 This warning category was added in the specified Perl version (a
55 development release). Without the 'if', trying to use it in an earlier
56 release would generate an unknown warning category error.
57
59 The current implementation does not allow specification of the required
60 version of the module.
61
63 Module::Requires can be used to conditionally load one or modules, with
64 constraints based on the version of the module. Unlike "if" though,
65 Module::Requires is not a core module.
66
67 Module::Load::Conditional provides a number of functions you can use to
68 query what modules are available, and then load one or more of them at
69 runtime.
70
71 provide can be used to select one of several possible modules to load,
72 based on what version of Perl is running.
73
75 Ilya Zakharevich <mailto:ilyaz@cpan.org>.
76
78 This software is copyright (c) 2002 by Ilya Zakharevich.
79
80 This is free software; you can redistribute it and/or modify it under
81 the same terms as the Perl 5 programming language system itself.
82
83
84
85perl v5.26.3 2018-03-01 if(3pm)