On Tue, Sep 21, 2004 at 12:37:09PM +0200, Ph. Marek wrote:
> But that gets me to the next question, ie I don't understand the
> difference between exhaustive and overlap.
>
> Is it that overlap fixes the first point of the pattern match and does
> further scanning for all possibilities, and exhaustive then *after*
> this processing searches for another first point?

:overlap gives you all of the matches as if you'd anchored the pattern
at the first character, then the second, then the third, and so on until
there are no more characters.  So, for 

        "abbabbabba" ~~ m:ov/a.*a/

It'll match "abbabbabba" at the first position, then fail on the two
"b" characters, and succeed on the next "a" giving you "abbabba", etc.

:exhaustive is the same but you get "in between" greediness results
too.  For instance,

        "abbabbabba" ~~ m:ex/a.*a/

when matched starting at the first character will give you "abbabbabba"
because of the greediness of *. But there are also "abba" and "abbabba"
that match along the way.

So ... here's a little table comparing the two (ignoring the
positions where there is no match).  Maybe it'll help. Assuming $_
contains "abbabbabba", we have

        Position        m:ov/a.*a/              m:ex/a.*a/
          0             abbabbabba              abbabbabba
                                                abbabba
                                                abba
          3             abbabba                 abbabba
                                                abba
          6             abba                    abba

You'll note that :exhaustive matches the string "abba" at different
locations. One thing S5 didn't mention was how to know at which position
each substring matched. I'm sure that's filed away in the magic $0
object though.

Hopefully, I'm being clear.

-Scott
-- 
Jonathan Scott Duff
[EMAIL PROTECTED]

Reply via email to