CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
use Something;

 



SirAnvil
Deleted

Dec 31, 2000, 8:17 PM

Post #1 of 2 (282 views)
use Something; Can't Post

Question!

I've seen scripts use a file that it came with such as

use somefile.pm;

and in the somefile.pm it has a bunch of pre-defined variables like
$variable1="apples";
$variable2="oranges";
and so on. So when I say use somefile.pm does that load the contents of that file into a cache?

SirAnvil


japhy
Enthusiast

Jan 1, 2001, 7:58 AM

Post #2 of 2 (278 views)
Re: use Something; [In reply to] Can't Post

The use compile-time directive is like calling require(), but: a) it happens at compile-time, b) it also calls the import() method of the module, if it exists, and c) it only works with modules (files ending in .pm).

It's used like so:


Code
use Some::Module;  # the file is Some/Module.pm 
use Foobar 'blat'; # the file is Foobar.pm

# are like

BEGIN {
require Some::Module;
Some::Module->import;
}
BEGIN {
require Foobar;
Foobar->import('blah');
}

The import() method allows you to access specific parts of the module to be copied into your program, instead of having to access them from the module's namespace. Some modules import things automatically.

To learn more about modules, please read perldoc perlmod.

Jeff "japhy" Pinyan -- accomplished hacker, teacher, lecturer, and author

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives