How to use 2 DIFFERENT VERSIONS of the SAME MODULE in the same perl program ?

Y

Yves Petinot

Hi guys,

hopefully somebody will have a clue on how to solve this in a NICE
way.

Here goes :

I have 2 versions of the same perl module. Now what that module
exactly does is somewhat irrelevant to my question, but if u must know
this module is a DBM module. Ok so you got it: i basically have a
database in one format and i want to switch to the upgraded format.
Unfortunately the module which handles that new format is the next
version of the module that handles the old format ... talk of a
headache !

Now my problem is that - obviously ??? - i cannot get perl to load the
same module twice in a single interpreter. Renaming the old or new
module is NOT an option since i have a whole set of libraries which
depend on that one module. Of course i can use a third - intermediary
+ standard - database format to move from my old format to my new
format in a 2 steps (export then import) fashion.

But i wish i could find a way of dealing with 2 versions of the same
module in the same perl program :p

Any help on this would be very much appreciated ...
 
M

Matt Garrish

Yves Petinot said:
Hi guys,

hopefully somebody will have a clue on how to solve this in a NICE
way.

Here goes :

I have 2 versions of the same perl module. Now what that module
exactly does is somewhat irrelevant to my question, but if u must know
this module is a DBM module. Ok so you got it: i basically have a
database in one format and i want to switch to the upgraded format.
Unfortunately the module which handles that new format is the next
version of the module that handles the old format ... talk of a
headache !

Now my problem is that - obviously ??? - i cannot get perl to load the
same module twice in a single interpreter. Renaming the old or new
module is NOT an option since i have a whole set of libraries which
depend on that one module. Of course i can use a third - intermediary
+ standard - database format to move from my old format to my new
format in a 2 steps (export then import) fashion.

But i wish i could find a way of dealing with 2 versions of the same
module in the same perl program :p

I can't say that I follow your problem. From what I read, you have one
module that handles data in some older format. You then rewrote this module
to use a new format. So why would you ever need to load both into the same
script? Or are you asking how you can use one or the other based on what
data you're dealing with? If that's the case, read up on using a module by
version number:

perldoc -f use

Matt
 
Y

Yves Petinot

I need this to write a single program that will read in one format and write
to the other. To do so both version have to be loaded in a single
interpreter (and i don't want to go into writing a 2 threaded program)

Yves.
 
J

John Bokma

Yves said:
I need this to write a single program that will read in one format and write
to the other. To do so both version have to be loaded in a single
interpreter (and i don't want to go into writing a 2 threaded program)

Wild guess, not tried, but can't you write two wrapper modules, each
including one version?
 
Y

Yves Petinot

:p

i did try this, but the wrapper itself loads in one version of the module.
Hence when i want to load in the second version, well ... it won't. In other
words the wrapper approach has no effect has to how modules are loaded by
the interpreter.

Yves.
 
G

gnari

John Bokma said:
Wild guess, not tried, but can't you write two wrapper modules, each
including one version?

won't work.

needs to make a copy of one of the modules, changing both
filename and packagename.

gnari
 
G

Gunnar Hjalmarsson

Yves said:
Now my problem is that - obviously ??? - i cannot get perl to load
the same module twice in a single interpreter.

Wouldn't something along this line be possible:

my %oldINC = %INC;
require '/path/to/old/version/module.pm';

# read old format of the database

%INC = %oldINC;
require module.pm; # load new version

# save the database in the new format
 
M

Matt Garrish

Yves Petinot said:
I need this to write a single program that will read in one format and write
to the other. To do so both version have to be loaded in a single
interpreter (and i don't want to go into writing a 2 threaded program)

You'll never be able to have the same module loaded twice *at the same time*
(the same package and function names just can't exist simultaneously). You
can try reloading the module, but that can cause you other problems. I
suspect you're just going to have to bite the bullet and resort to one of
the other options you've mentioned.

Matt
 
R

Richard S Beckett

But i wish i could find a way of dealing with 2 versions of the same
module in the same perl program :p

If you wrote the module, why not make the new module capable of handling
both types of database?
 
B

Brian McCauley

I have 2 versions of the same perl module. Now what that module
exactly does is somewhat irrelevant to my question, but if u must know
this module is a DBM module. Ok so you got it: i basically have a
database in one format and i want to switch to the upgraded format.
Unfortunately the module which handles that new format is the next
version of the module that handles the old format ... talk of a
headache !


I would fork() (or more likely open() with a mode of '-|' or '|-')
before I load either module then load one module in the parent and the
other in the child.

If a one-way FIFO communication between the two parts is not sufficient I'd
create a Safe comapartment (with unrestricted opmask).

There's also something called Safe::World which may help in this sort
of situation but I'm not sure.

--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
 

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,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top