Problem with "require" and multiple modules.

D

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

nobull

Don said:
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);
}

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

Ralph Henneberg

Don said:
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
 

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,777
Messages
2,569,604
Members
45,205
Latest member
ShereeStan

Latest Threads

Top