use require and loading modules

B

buildmorelines

As I understand, if I load a module with "use" it will be parsed
imidiatly on/read during compiled/eats up initial start-up time, if I
use "require" it is loaded when perl reaches the require statement?

I am trying to load a module, but I want to save time on start up, so
I want to load the module much later on in the program, and its not
always required.
 
G

Gunnar Hjalmarsson

buildmorelines said:
As I understand, if I load a module with "use" it will be parsed
imidiatly on/read during compiled/eats up initial start-up time, if
I use "require" it is loaded when perl reaches the require
statement?

I am trying to load a module, but I want to save time on start up,
so I want to load the module much later on in the program, and its
not always required.

?? Then change your code, for god's sake.
 
B

buildmorelines

As I understand, if I load a module with "use" it will be parsed
imidiatly on/read during compiled/eats up initial start-up time, if I
use "require" it is loaded when perl reaches the require statement?

I am trying to load a module, but I want to save time on start up, so
I want to load the module much later on in the program, and its not
always required.
I didnt have enough cola :(

What I was asking is, is there any way to load modules after the
initial compilation, as needed/on the fly/dynamically, so I wont be
loading code that will not get used?

As I understood, if I uses "use" to do it, the module will be parsed
and compiled when the program is run for the first time. I dont want
the module to be parsed and compiled when the program is run for the
first time, I want the module to be paresed and compiled when I say
its ok. how would I do this in Perl?
 
G

Gunnar Hjalmarsson

buildmorelines said:
is there any way to load modules after the initial compilation, as
needed/on the fly/dynamically, so I wont be loading code that will
not get used?

require MyModule;

does just that, i.e. the module gets loaded only if and when that
statement is executed.
 
S

Shawn Corey

Gunnar said:
require MyModule;

does just that, i.e. the module gets loaded only if and when that
statement is executed.

See perldoc perlmod.

use MyModule;

is equivalent to

BEGIN{ require MyModule; import MyModule; }

and

use MyModule @LIST;

is

BEGIN{ require MyModule; import MyModule @LIST; }

--- Shawn
 
B

Brian McCauley

Gunnar said:
require MyModule;

does just that, i.e. the module gets loaded only if and when that
statement is executed.

I think the OP is really looking for autouse.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top