Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > How to use 2 DIFFERENT VERSIONS of the SAME MODULE in the same perl program ?

Reply
Thread Tools

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

 
 
Yves Petinot
Guest
Posts: n/a
 
      06-28-2004
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

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


 
Reply With Quote
 
 
 
 
Matt Garrish
Guest
Posts: n/a
 
      06-29-2004

"Yves Petinot" <(E-Mail Removed)> wrote in message
news:cbpn9p$loc$(E-Mail Removed)...
> 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
>


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


 
Reply With Quote
 
 
 
 
Yves Petinot
Guest
Posts: n/a
 
      06-29-2004
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.


"Matt Garrish" <(E-Mail Removed)> a écrit dans le message de
news:wp2Ec.8987$(E-Mail Removed).. .
>
> "Yves Petinot" <(E-Mail Removed)> wrote in message
> news:cbpn9p$loc$(E-Mail Removed)...
> > 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
> >

>
> 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
>
>



 
Reply With Quote
 
John Bokma
Guest
Posts: n/a
 
      06-29-2004
Yves Petinot wrote:

> 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?

--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
 
Reply With Quote
 
Yves Petinot
Guest
Posts: n/a
 
      06-29-2004


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.

"John Bokma" <(E-Mail Removed)> a écrit dans le message de
news:40e0bde7$0$874$(E-Mail Removed)...
> Yves Petinot wrote:
>
> > 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?
>
> --
> John MexIT: http://johnbokma.com/mexit/
> personal page: http://johnbokma.com/
> Experienced Perl programmer available: http://castleamber.com/
> Happy Customers: http://castleamber.com/testimonials.html



 
Reply With Quote
 
gnari
Guest
Posts: n/a
 
      06-29-2004
"John Bokma" <(E-Mail Removed)> wrote in message
news:40e0bde7$0$874$(E-Mail Removed)...
> Yves Petinot wrote:
>
> > 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?


won't work.

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

gnari




 
Reply With Quote
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      06-29-2004
Yves Petinot wrote:
> 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

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
Matt Garrish
Guest
Posts: n/a
 
      06-29-2004

"Yves Petinot" <(E-Mail Removed)> wrote in message
news:cbqdv7$1cjk$(E-Mail Removed)...
> 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


 
Reply With Quote
 
Richard S Beckett
Guest
Posts: n/a
 
      06-29-2004
> But i wish i could find a way of dealing with 2 versions of the same
> module in the same perl program


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

--
R.
GPLRank +79.699


 
Reply With Quote
 
Brian McCauley
Guest
Posts: n/a
 
      06-30-2004
"Yves Petinot" <(E-Mail Removed)> writes:


> 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\\
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Different results from different gcc versions ks C++ 9 03-20-2010 02:09 PM
running same script on same data on two different machines -->different result Christopher Brewster Python 5 11-14-2008 08:19 PM
Different flavors of a gem for different versions of Ruby Ken Bloom Ruby 2 11-04-2008 01:01 AM
Get ClassID of different versions of program with same ProgID ilocke Python 2 06-01-2007 11:15 PM



Advertisments