AcornSearch - Acorn and RISC OS information searching
RISC OS Search
containing
"Nutty quip goes here!"
Home  |  About  |  Filebase Archive  |  StrongHelp Manuals  |  Newsgroups  |  Module Database
require EXPR
require

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};
local($realfilename,$result);
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;
$result;
}

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 bare word, the require assumes a ".pm" extension 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 the use entry and 
perlmod.


[sh-index] Back to list of manuals