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

Discussion in 'Perl Misc' started by Yves Petinot, Jun 28, 2004.

  1. Yves Petinot

    Yves Petinot Guest

    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 ...
     
    Yves Petinot, Jun 28, 2004
    #1
    1. Advertising

  2. Yves Petinot

    Matt Garrish Guest

    "Yves Petinot" <> wrote in message
    news:cbpn9p$loc$...
    > 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
     
    Matt Garrish, Jun 29, 2004
    #2
    1. Advertising

  3. Yves Petinot

    Yves Petinot Guest

    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" <> a écrit dans le message de
    news:wp2Ec.8987$...
    >
    > "Yves Petinot" <> wrote in message
    > news:cbpn9p$loc$...
    > > 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
    >
    >
     
    Yves Petinot, Jun 29, 2004
    #3
  4. Yves Petinot

    John Bokma Guest

    Re: How to use 2 DIFFERENT VERSIONS of the SAME MODULE in the sameperl program ?

    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
     
    John Bokma, Jun 29, 2004
    #4
  5. Yves Petinot

    Yves Petinot Guest

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

    "John Bokma" <> a écrit dans le message de
    news:40e0bde7$0$874$...
    > 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
     
    Yves Petinot, Jun 29, 2004
    #5
  6. Yves Petinot

    gnari Guest

    Re: How to use 2 DIFFERENT VERSIONS of the SAME MODULE in the sameperl program ?

    "John Bokma" <> wrote in message
    news:40e0bde7$0$874$...
    > 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
     
    gnari, Jun 29, 2004
    #6
  7. Re: How to use 2 DIFFERENT VERSIONS of the SAME MODULE in the sameperl program ?

    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
     
    Gunnar Hjalmarsson, Jun 29, 2004
    #7
  8. Yves Petinot

    Matt Garrish Guest

    "Yves Petinot" <> wrote in message
    news:cbqdv7$1cjk$...
    > 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
     
    Matt Garrish, Jun 29, 2004
    #8
  9. > 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?

    --
    R.
    GPLRank +79.699
     
    Richard S Beckett, Jun 29, 2004
    #9
  10. "Yves Petinot" <> 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\\
     
    Brian McCauley, Jun 30, 2004
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Davison
    Replies:
    3
    Views:
    804
    Amitabh
    Jul 16, 2004
  2. hilz
    Replies:
    4
    Views:
    665
    Oscar kind
    Nov 21, 2004
  3. ilocke
    Replies:
    2
    Views:
    448
    ilocke
    Jun 2, 2007
  4. ks
    Replies:
    9
    Views:
    417
    Jorgen Grahn
    Mar 20, 2010
  5. Ken Bloom
    Replies:
    2
    Views:
    130
    Ken Bloom
    Nov 4, 2008
Loading...

Share This Page