469,923 Members | 1,584 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,923 developers. It's quick & easy.

Problem with "require" and multiple modules.

Don
I have a set of modules that all have the same interface, and package name:
_______________________________
package dataSourcePackage;

# Initialize global variables

$hashOne{'uniquekey1'} = "value1";
$hashOne{'uniquekey2'} = "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:
_________________________________
../processDataSource dataSource1

(Which will do the following:)

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

@datapoints = dataSourcePackage::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";
dataSourcePackage::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 dataSourcePackage, it will start fresh? (NOTE: there are
a VERY large number of these dataSourcePackages, and it wouldn't be easy to
modify ALL the packages, any help would be greatly appreciated.)

Thanks,
Don.

Jul 19 '05 #1
2 2485
"Don" <pl*******************@nerdlycrap.com> wrote in message news:<1O*********************@twister.nyroc.rr.com >...
I have a set of modules that all have the same interface, and package name:
Bad idea.
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";
dataSourcePackage::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 dataSourcePackage, it will start fresh?
This is FAQ: "How do I clear a package?"

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


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.
Jul 19 '05 #2
"Don" <pl*******************@nerdlycrap.com> wrote in message news:<1O*********************@twister.nyroc.rr.com >...
I have a set of modules that all have the same interface, and package name:
_______________________________
package dataSourcePackage;

# Initialize global variables

$hashOne{'uniquekey1'} = "value1";
$hashOne{'uniquekey2'} = "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:
_________________________________
./processDataSource dataSource1

(Which will do the following:)

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

@datapoints = dataSourcePackage::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";
dataSourcePackage::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 dataSourcePackage, it will start fresh? (NOTE: there are
a VERY large number of these dataSourcePackages, and it wouldn't be easy to
modify ALL the packages, any help would be greatly appreciated.)

Thanks,
Don.


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

Ralph
Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Phil Powell | last post: by
15 posts views Thread by Michael | last post: by
5 posts views Thread by Jim Carlock | last post: by
1 post views Thread by yaru22 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.