Ewout wrote:
> Assume that the parameter value is ABCR. The regex should be such that
> for example a string like ABCC should give a match. But if the
> parameter value is XYZR, then the string XYZC should give a match. To
> summarize: the regex should take part of the pattern from another
> string that is supplied separately from the regex. Is there any way to
> achieve this?
I'm a crappy perl programmer, but I think I understand your problem
despite the fact that you are being very ambiguous about it.
You seem to be doing what many "bioinformaticians" have been trying to
do, which is compare two sequences and find patterns of similarity
between these two sequences....so you might want to look in the bioperl
module (
www.bioperl.org).
If you do as you wish and "parameterize" it, you will have to find a
metric and a weighting method which makes it a hard problem...
Otherwise, you could do what I think you are thinking of doing, and you
could generate a set of wild card matches which you could use to regex.
There are obvious memory issues (x**n permutations of x characters of
length n), but one trick is rather than build an array or hash of
$patterns, you splice them all into one very big $pattern.
i.e. $pattern = "x1|x2|x3....|xn";
$string =~ /$pattern/;
Doing this is immensely faster than iterating through an array or the like:
i.e. foreach $pattern (@pattern){
$string =~ /$pattern/;
This was mentioned somewhere...Perl Cookbook? Or it may have been the
advanced book of Perl Programming...
Austin