I am hoping to maybe get some ideas on how to accomplish the task I have more efficiently.
I have a script that queries a DB table for new files received from clients. The script stores the info for these files in a hash of hashes, with one of the values being a unique code for that client.
Then the script loops through the hash. Each client sends a unique type or set of files, so I have a subroutine for each client which is in its own file.
For example: For clientX I create a file named "clientX.pm". In that file is a sub called "file_mod". In my main script I encounter the client code 'X' and this code is used:
In general, this works fine. However, one of the problems I encounter stems from the fact that I use the same sub name 'file_mod' in every client module. Uh-oh...you can guess what happens when I have several clients in my hash. Yes, the script calls the sub for the wrong (previously called) client.
So, do I make the sub names variable, such as 'file_mod_clientX', or is there some better way to approach this?
For perspective, each client has to be handled uniquely and there are 500+ clients.
Any thoughts would be much appreciated!
Scott
I have a script that queries a DB table for new files received from clients. The script stores the info for these files in a hash of hashes, with one of the values being a unique code for that client.
Then the script loops through the hash. Each client sends a unique type or set of files, so I have a subroutine for each client which is in its own file.
For example: For clientX I create a file named "clientX.pm". In that file is a sub called "file_mod". In my main script I encounter the client code 'X' and this code is used:
Code:
# Dynamically build file name for this client
my $mod = 'client' . $ulFile{$fid}{code} . '.pm';
# Make sure the client-specific code exists
if (-e $mod)
{
# Load the client-specific code
require $mod;
# Run the sub for handling the data
file_mod($fid);
}
In general, this works fine. However, one of the problems I encounter stems from the fact that I use the same sub name 'file_mod' in every client module. Uh-oh...you can guess what happens when I have several clients in my hash. Yes, the script calls the sub for the wrong (previously called) client.
So, do I make the sub names variable, such as 'file_mod_clientX', or is there some better way to approach this?
For perspective, each client has to be handled uniquely and there are 500+ clients.
Any thoughts would be much appreciated!
Scott