Hi, 

c r <[EMAIL PROTECTED]> 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?

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.

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.

HTH,
Thomas

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to