replacing modules?

T

Torsten Mohr

Hi,

if i load a module by something like:

use module;

then i could also just load all the functions in module.pm
into my own script and everything is fine.
This works for some modules.

But how for example do i replace:

use vars qw/$some $list $of $variables/;

What else do i need to look for if i want to replace some
modules?


Best regards,
Torsten.
 
A

Anno Siegel

Torsten Mohr said:
Hi,

if i load a module by something like:

use module;

then i could also just load all the functions in module.pm
into my own script and everything is fine.
This works for some modules.

It works better if you put the text of the foreign module into a BEGIN
block where the "use" statement used to be. Immediately following,
add another block

BEGIN { Module->import( ...) if Module->can( 'import') }

The dots represent the arguments to the former "use" statement.
But how for example do i replace:

use vars qw/$some $list $of $variables/;

There is no general recipe. This statements is needed to make the
module work if it is *not* part of your file. To replace it, you
must understand why it is there and replace it with something that
does the same thing in the new situation. It may need no replacement
at all.
What else do i need to look for if i want to replace some
modules?

Start with the pair of BEGIN blocks sketched above. Then debug it:
run it and repair what's broken.

Anno
 
T

Tassilo v. Parseval

Also sprach Anno Siegel:
It works better if you put the text of the foreign module into a BEGIN
block where the "use" statement used to be. Immediately following,
add another block

BEGIN { Module->import( ...) if Module->can( 'import') }

You can even drop the 'if' altogether. The 'import' method is special in
that perl will silently turn 'Module->import' into a no-op if this
method isn't inherited nor defined by Module.

Tassilo
 
A

Anno Siegel

Tassilo v. Parseval said:
Also sprach Anno Siegel:


You can even drop the 'if' altogether. The 'import' method is special in
that perl will silently turn 'Module->import' into a no-op if this
method isn't inherited nor defined by Module.

Ah... I didn't know this. I must have falsely accused a few good
programmers of sloppiness because of that :)

Anno
 

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

Similar Threads

Learning to write modules by example. 2
RegExp pattern / replace function 0
naming modules 6
How to use variables across modules 2
conditional modules 3
Python modules 5
Loading Modules 0
Importing modules 11

Members online

No members online now.

Forum statistics

Threads
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top