I'm not sure this will work in my situation.
(Im not sure it wont either)
I'm no namespace / symbol table expert!
Anyway, here is what i'm doing. Im writing an engine for database migration / normalization. Our company receives data from about 100 (and growing) different sources, each providing data in different formats.
The subroutines that are being called within the strict / no strict, are functions to change the format of individual fields from the raw source -> our common database. For example, addresses need to be parsed into street name, number, direction, bulding, unit, city, state, zip, etc. And since this info comes from so many different sources with wildly varying formats for just that field, I have a variety of parsing functions. So, im having the engine call main::address_parser_73(...) as necessary.
(of course i'd never name a function address_parser_73).
So, i don't see a good way to do the above on the fly for using one of hundreds of potential functions.
But, as i said, i haven't done this sort of thing much - Im totally open to ideas.
thanks
| [reply] |
use strict;
my @parsers;
push @parsers, \&parser1; # Create a reference to parser 1 and push it
+ onto the array
push @parsers, \&parser2; # Ditto for parser 2
...
sub parser1 { parse..parse..parse };
sub parser2 { parse_somewhat_differently };
When a record from a source, say source 2 comes in, you access it's parser with:
$parsers[$source_id]->( arguments ); # $source_id contains the source,
+ e.g. 2
I have a feeling that you can even automate the process of creating the @parsers array by playing symbol table games, but I'm not awake enough any more to take a decent shot at it. Perhaps some more experienced (and awake) monk will step in here.
CU Robartes- | [reply] [d/l] [select] |
Store subrefs in a hash instead.
my %parsers = (
address => sub {
# ...
},
f_dcompany => sub {
# ...
},
xmlbzzwrd => sub {
# ...
},
);
Then you can call these like chromatic pointed out:
$parser{$whatever}->(@pass, $some, @params);
Makeshifts last the longest. | [reply] [d/l] [select] |