Problem with "require" and multiple modules.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Don

    Problem with "require" and multiple modules.

    I have a set of modules that all have the same interface, and package name:
    _______________ _______________ _
    package dataSourcePacka ge;

    # Initialize global variables

    $hashOne{'uniqu ekey1'} = "value1";
    $hashOne{'uniqu ekey2'} = "value1";

    sub requiredMethod1 ()
    {
    ....
    }
    ....

    return 1;
    _______________ _______________ ___
    The processing in each module is different, but the interface MUST remain
    the same. I have scripts which call each module based on an input to the
    script:
    _______________ _______________ ___
    ../processDataSour ce dataSource1

    (Which will do the following:)

    require "/path/to/mods/ARGV[0]"; # I do have error testing this is just a
    simplified version

    @datapoints = dataSourcePacka ge::getPoints(5 );

    # Process points.

    _______________ _______________ ___

    My problem is I now have to write a script which runs multiple packages
    during the same execution, and sometimes will call the same package twice.
    The issue I am having is that most of the modules have hardcoded data in the
    section I have marked as "Initialize global data", and contain hashes with
    the same name. So when I do something like:
    --------------------------------
    foreach $datasource (@datasources)
    {
    require "/path/to/mods/$datasource";
    dataSourcePacka ge::syncPoints(-1);
    }
    --------------------------
    dataSource2 will try to access dataSource1 points, which causes runtime
    errors. Is there a way to destroy a package after it is loaded, so that the
    next time I load a dataSourcePacka ge, it will start fresh? (NOTE: there are
    a VERY large number of these dataSourcePacka ges, and it wouldn't be easy to
    modify ALL the packages, any help would be greatly appreciated.)

    Thanks,
    Don.



  • nobull@mail.com

    #2
    Re: Problem with "require&q uot; and multiple modules.

    "Don" <please-reply-in-group@nerdlycra p.com> wrote in message news:<1OaBb.196 964$1N3.194730@ twister.nyroc.r r.com>...[color=blue]
    > I have a set of modules that all have the same interface, and package name:[/color]

    Bad idea.
    [color=blue]
    > My problem is I now have to write a script which runs multiple packages
    > during the same execution, and sometimes will call the same package twice.
    > The issue I am having is that most of the modules have hardcoded data in the
    > section I have marked as "Initialize global data", and contain hashes with
    > the same name. So when I do something like:
    > --------------------------------
    > foreach $datasource (@datasources)
    > {
    > require "/path/to/mods/$datasource";
    > dataSourcePacka ge::syncPoints(-1);
    > }
    > --------------------------
    > dataSource2 will try to access dataSource1 points, which causes runtime
    > errors. Is there a way to destroy a package after it is loaded, so that the
    > next time I load a dataSourcePacka ge, it will start fresh?[/color]

    This is FAQ: "How do I clear a package?"

    You'll also need to delete the entry in %INC.
    [color=blue]
    > (NOTE: there are
    > a VERY large number of these dataSourcePacka ges, and it wouldn't be easy to
    > modify ALL the packages, any help would be greatly appreciated.)[/color]

    If the packages don't rely too many other modules at compile time you
    could load each in it's own Safe compartment.

    This newsgroup does not exist (see FAQ). Please do not start threads
    here.

    Comment

    • Ralph Henneberg

      #3
      Re: Problem with &quot;require&q uot; and multiple modules.

      "Don" <please-reply-in-group@nerdlycra p.com> wrote in message news:<1OaBb.196 964$1N3.194730@ twister.nyroc.r r.com>...[color=blue]
      > I have a set of modules that all have the same interface, and package name:
      > _______________ _______________ _
      > package dataSourcePacka ge;
      >
      > # Initialize global variables
      >
      > $hashOne{'uniqu ekey1'} = "value1";
      > $hashOne{'uniqu ekey2'} = "value1";
      >
      > sub requiredMethod1 ()
      > {
      > ...
      > }
      > ...
      >
      > return 1;
      > _______________ _______________ ___
      > The processing in each module is different, but the interface MUST remain
      > the same. I have scripts which call each module based on an input to the
      > script:
      > _______________ _______________ ___
      > ./processDataSour ce dataSource1
      >
      > (Which will do the following:)
      >
      > require "/path/to/mods/ARGV[0]"; # I do have error testing this is just a
      > simplified version
      >
      > @datapoints = dataSourcePacka ge::getPoints(5 );
      >
      > # Process points.
      >
      > _______________ _______________ ___
      >
      > My problem is I now have to write a script which runs multiple packages
      > during the same execution, and sometimes will call the same package twice.
      > The issue I am having is that most of the modules have hardcoded data in the
      > section I have marked as "Initialize global data", and contain hashes with
      > the same name. So when I do something like:
      > --------------------------------
      > foreach $datasource (@datasources)
      > {
      > require "/path/to/mods/$datasource";
      > dataSourcePacka ge::syncPoints(-1);
      > }
      > --------------------------
      > dataSource2 will try to access dataSource1 points, which causes runtime
      > errors. Is there a way to destroy a package after it is loaded, so that the
      > next time I load a dataSourcePacka ge, it will start fresh? (NOTE: there are
      > a VERY large number of these dataSourcePacka ges, and it wouldn't be easy to
      > modify ALL the packages, any help would be greatly appreciated.)
      >
      > Thanks,
      > Don.[/color]

      to enforce reoloading of the packages try to delete from the %INC hash :
      delete $INC{"/path/to/mods/$datasource");

      Ralph

      Comment

      Working...