The ideal container program would slurp the regexfile, then apply it to
whatever text that is to be searched. In the case of a match, it would somehow
(and this is my problem) be able to retrieve the captured values (in the proper
order) that are in the regex. This does work in the above regex example,
but that is ugly because it needs the program to know what to do with '$hashname'.
My example regex above has this silly ${$hashname} stuff, which (in the test
container program I have) is changed into a real variable name for the hash. I
have copied the sub below. I've added some comments, variables contain what they
are named after.
And it may well be that it is just not feasible without taking recourse to
globals.
This sub is called before compiling the regexes. The substitution is its
main function.
sub get_regexes_prepare { # replaces all ${$hashname}{'abc'}
no strict 'refs';
my ($pckg,$rregexes) = @_; # packagename and hashref are passed
my @regexes = @{$rregexes};
my @hashnames = ();
$#hashnames = $#regexes; # same size
for (my $i=0; $i < $#regexes+1; $i++) {
my $hashname = "${pckg}::hashname".$i; # construct hashname
$hashnames[$i] = $hashname;
$regexes[$i] =~ s/\$hashname/\$$hashname/g;
tie %${$hashname}, "Tie::IxHash"; # keep order
}
return (\@regexes,\@hashnames);
}
I'll later (tomorrow or so) post more complete code. But as you can probably
guess from this sub code, it needs some cleaning up and removing of some
experimental stuff :)
Thanks
|