Manual

- Overview
- Tutorials
- FAQs
- History / Changes
- License

Reference

- Language
- Functions
- Operators
- Special Variables
- Pragmas
- Utilities
- Internals
- Platform Specific

Modules

- A • B • C • D • E
- F • G • H • I • L
- M • N • O • P • S
- T • U • X

News / Blogs

- Perl Buzz
- Perl Iron Man
- Perlsphere
- Planet Perl
- TPF news
- Use Perl

See also

- CPAN
- Perl.org
- Perl.com
- Perl 5 Wiki
- Perl Jobs
- Perl Mongers
- Perl Monks

Contact

- Site designed and maintained by Jon Allen (JJ)
- http://perl.jonallen.info

- View the project page and FAQs

# use

Perl 5 version 10.1 documentation
Go to top

# use

Perl functions A-Z | Perl functions by category | The 'perlfunc' manpage

- use Module VERSION LIST

- use Module VERSION
- use Module LIST
- use Module
- use VERSION

  Imports some semantics into the current package from the named module, generally by aliasing certain subroutine or variable names into your package. It is exactly equivalent to

          BEGIN { require Module; Module->import( LIST ); }

  except that Module must be a bareword.

  In the peculiar `use VERSION` form, VERSION may be either a numeric argument such as 5.006, which will be compared to `$]` , or a literal of the form v5.6.1, which will be compared to `$^V` (aka $PERL_VERSION). A fatal error is produced if VERSION is greater than the version of the current Perl interpreter; Perl will not attempt to parse the rest of the file. Compare with "require", which can do a similar check at run time. Symmetrically, `no VERSION` allows you to specify that you want a version of perl older than the specified one.

  Specifying VERSION as a literal of the form v5.6.1 should generally be avoided, because it leads to misleading error messages under earlier versions of Perl (that is, prior to 5.6.0) that do not support this syntax. The equivalent numeric version should be used instead.

          use v5.6.1;		# compile time version check    use 5.6.1;		# ditto    use 5.006_001;	# ditto; preferred for backwards compatibility

  This is often useful if you need to check the current Perl version before `use`ing library modules that won't work with older versions of Perl. (We try not to do this more than we have to.)

  Also, if the specified perl version is greater than or equal to 5.9.5, `use VERSION` will also load the `feature` pragma and enable all features available in the requested version. See feature.

  The `BEGIN` forces the `require` and `import` to happen at compile time. The `require` makes sure the module is loaded into memory if it hasn't been yet. The `import` is not a builtin--it's just an ordinary static method call into the `Module` package to tell the module to import the list of features back into the current package. The module can implement its `import` method any way it likes, though most modules just choose to derive their `import` method via inheritance from the `Exporter` class that is defined in the `Exporter` module. See Exporter. If no `import` method can be found then the call is skipped, even if there is an AUTOLOAD method.

  If you do not want to call the package's `import` method (for instance, to stop your namespace from being altered), explicitly supply the empty list:

          use Module ();

  That is exactly equivalent to

          BEGIN { require Module }

  If the VERSION argument is present between Module and LIST, then the `use` will call the VERSION method in class Module with the given version as an argument. The default VERSION method, inherited from the UNIVERSAL class, croaks if the given version is larger than the value of the variable `$Module::VERSION` .

  Again, there is a distinction between omitting LIST (`import` called with no arguments) and an explicit empty LIST `()` (`import` not called). Note that there is no comma after VERSION!

  Because this is a wide-open interface, pragmas (compiler directives) are also implemented this way. Currently implemented pragmas are:

          use constant;    use diagnostics;    use integer;    use sigtrap  qw(SEGV BUS);    use strict   qw(subs vars refs);    use subs     qw(afunc blurfl);    use warnings qw(all);    use sort     qw(stable _quicksort _mergesort);

  Some of these pseudo-modules import semantics into the current block scope (like `strict` or `integer` , unlike ordinary modules, which import symbols into the current package (which are effective through the end of the file).

  There's a corresponding `no` command that unimports meanings imported by `use`, i.e., it calls `unimport Module LIST` instead of `import`. It behaves exactly as `import` does with respect to VERSION, an omitted LIST, empty LIST, or no unimport method being found.

          no integer;    no strict 'refs';    no warnings;

  See perlmodlib for a list of standard modules and pragmas. See perlrun for the `-M` and `-m` command-line options to perl that give `use` functionality from the command-line.

Recently read

Tools

- Preferences