Help with Dynamic load pm.

F

Franklin Lee

Hi all,

I met below problem.

When first run my program, I will load my own lib, such as
/opt/myapp/lib1/mylib.pm.
code:
push(@INC, "/opt/myapp/lib1");
require mylib;
......

In the middle of my program, I will create new lib, such as
/var/tmp/myapp/lib/mylib.pm.
This file is new lib file I should use and contain same functions as
/opt/myapp/lib1/mylib.pm
Now I want to use the functions in /var/tmp/myapp/lib/mylib.pm instead of
/opt/myapp/lib1/mylib.pm
Then how should I do?

Thank you!

Franklin
 
A

Anno Siegel

Franklin Lee said:
Hi all,

I met below problem.

When first run my program, I will load my own lib, such as
/opt/myapp/lib1/mylib.pm.
code:
push(@INC, "/opt/myapp/lib1");
require mylib;
.....

In the middle of my program, I will create new lib, such as
/var/tmp/myapp/lib/mylib.pm.
This file is new lib file I should use and contain same functions as
/opt/myapp/lib1/mylib.pm
Now I want to use the functions in /var/tmp/myapp/lib/mylib.pm instead of
/opt/myapp/lib1/mylib.pm
Then how should I do?

I guess you will have to start another process that uses the new library.
I don't know if dynamic loading supports re-loading a library anywhere,
but Perl's common interface to dynamic loading certainly doesn't.

Anno
 
B

Ben Morrow

You shouldn't use module names starting with a lowercase letter: these
are reserved for use by pragmas.
I guess you will have to start another process that uses the new library.
I don't know if dynamic loading supports re-loading a library anywhere,
but Perl's common interface to dynamic loading certainly doesn't.

I suspect the OP's use of 'dynamic loading' was misleading, and he was
not referring to loading .sos, merely .pms... in which case, you need to
do

{
no warnings 'redefine';
delete $INC{'mylib.pm'};
require mylib;
}

Ben
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,816
Latest member
SapanaCarpetStudio

Latest Threads

Top