in reply to Re: Communication of program(s) with regex codeblocks
in thread Communication of program(s) with regex codeblocks
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Communication of program(s) with regex codeblocks
by ikegami (Patriarch) on Oct 26, 2004 at 16:22 UTC | |
by erix (Prior) on Oct 28, 2004 at 21:26 UTC | |
by ikegami (Patriarch) on Oct 28, 2004 at 22:33 UTC | |
by erix (Prior) on Oct 29, 2004 at 20:20 UTC | |
by ikegami (Patriarch) on Oct 29, 2004 at 20:30 UTC |