Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

require

Loads and executes a Perl file or module, caching it in %INC so that subsequent calls for the same module are no-ops.

Behaviour depends on the argument type:

  1. Version number (numeric or v-string): asserts that the Perl version is at least that value. pperl claims 5.42 compatibility, so any 5.x requirement succeeds; 6+ dies.

  2. Bareword / string: converts Foo::Bar to Foo/Bar.pm, then searches @INC for the file. If already present in %INC, the call is a no-op. Otherwise the file is compiled and executed in a sub-interpreter, subs are registered, and %INC is updated.

Dies with "Can't locate ..." if the file is not found. Returns 1 on success.

Synopsis

require 5.036;              # version check
require Carp;               # load Carp.pm via @INC
require "config.pl";        # load a file by path

See Also

use, do, eval, @INC, %INC