icon Top 9 categories map      RocketAware > Perl >

require EXPR

Tips: Browse or Search all pages for efficient awareness of Perl functions, operators, and FAQs.


Search Perl pages


By activity
Professions, Sciences, Humanities, Business, ...

User Interface
Text-based, GUI, Audio, Video, Keyboards, Mouse, Images,...

Text Strings
Conversions, tests, processing, manipulation,...

Integer, Floating point, Matrix, Statistics, Boolean, ...

Algorithms, Memory, Process control, Debugging, ...

Stored Data
Data storage, Integrity, Encryption, Compression, ...

Networks, protocols, Interprocess, Remote, Client Server, ...

Hard World
Timing, Calendar and Clock, Audio, Video, Printer, Controls...

File System
Management, Filtering, File & Directory access, Viewers, ...

require EXPR
Demands some semantics specified by EXPR, or by $_ if EXPR is not supplied. If EXPR is numeric, demands that the current version of Perl ( $] or $PERL_VERSION) be equal or greater than EXPR.

Otherwise, demands that a library file be included if it hasn't already been included. The file is included via the do-FILE mechanism, which is essentially just a variety of eval(). Has semantics similar to the following subroutine:

    sub require {
        local($filename) = @_;
        return 1 if $INC{$filename};
        ITER: {
            foreach $prefix (@INC) {
                $realfilename = "$prefix/$filename";
                if (-f $realfilename) {
                    $result = do $realfilename;
                    last ITER;
            die "Can't find $filename in \@INC";
        die $@ if $@;
        die "$filename did not return true value" unless $result;
        $INC{$filename} = $realfilename;

Note that the file will not be included twice under the same specified name. The file must return TRUE as the last statement to indicate successful execution of any initialization code, so it's customary to end such a file with ``1;'' unless you're sure it'll return TRUE otherwise. But it's better just to put the `` 1;'', in case you add more statements.

If EXPR is a bareword, the require assumes a ``.pm'' extension and replaces ``::'' with ``/'' in the filename for you, to make it easy to load standard modules. This form of loading of modules does not risk altering your namespace.

For a yet-more-powerful import facility, see use and the perlmod manpage.

Source: Perl builtin functions
Copyright: Larry Wall, et al.
Next: reset EXPR

Previous: rename OLDNAME,NEWNAME

(Corrections, notes, and links courtesy of RocketAware.com)

[Overview Topics]

Up to: PERL

Rapid-Links: Search | About | Comments | Submit Path: RocketAware > Perl > perlfunc/require.htm
RocketAware.com is a service of Mib Software
Copyright 2000, Forrest J. Cavalier III. All Rights Reserved.
We welcome submissions and comments