c r <[EMAIL PROTECTED]> wrote:Thanks for replying!
Thomas B�tzler <[EMAIL PROTECTED]> wrote:
Hi,
c r asked:
> I need to match an expression and its reverse to a very long string.
> When a match occurs all matching should stop and the position
> of the match should be returned.
Could you please illustrate this with an example or two?
Don't mind the lack of position return. I have:
$expres = '10_normal_characters'; $rev_expres = reverse $expres; $long_string =
'ARGBB...........';
if ($long_string =~ /$expres/i) { next;}
if ($long_string =~ /$rev_expres/i) {next;}
(the "next" function takes a different $expres reverses it and does the matching
procedure again. This is repeted many thounsands of times and it takes days to
finish).
Unless you specify the /g modifier, the RE engine stops at
the first match. Use the pos function to find the position
of the match.
> Question1: can I match the forward and reverse expression to
> the string on the same time and thereby save half the time it
> normally would take to find a match or does the matching just
> get slower?
Well, you'd have to merge your expressions somehow - the easiest
way would be to try and match /expr-a|expr-b/ but then I suspect
that for all but simple cases two separate matches would be faster.
> Question2: is the "fork" function what I should use in order
> to match a string with multiple expressions simultaneously?
Well, there is a certain overhead involved in keeping your processes
synchronized that would only be outweighed if you had a multi CPU
machine where both processes could run at once in the first place.
Even then it's a hassle.
So in order to match a very long string with multiple expressions simultaneously and
faster than the matching procedure I have described above I need multiple computers?
If I were you I'd focus my energy in optimizing the expression.
If you're going to match many long strings with the same RE, you
could use the /o modifier to benefit. Also, you could try wether
a study() of the input strings speeds things up.
I don't know the "study" function, but I doubt it can solve the problem to
satisfatory. please correct me if I am wrong!
I acknowledge that this is a serious programming challenge. Do you have any other
ideas of how to tackle this problem (what about other hardware)?
HTH,
Thomas