in reply to Re^4: about style: use possessive or atomic?
in thread about style: use possessive or atomic?

I used a bigger regex, which contained some such groups. And for avoiding unexpected results, I wanted to use atomics/possessives. And I wanted to capture these groups. So instead of writing /(?> ($pat1) ) (?> ($pat2) )/x I decided to use possessive quantifiers to increase readability :) (my eyes dislike too many parentheses)
I don't have access to code, where I used it, but friend wrote to me, that with perl 5.20 he gained something wrong (warning/error).

Replies are listed 'Best First'.
Re^6: about style: use possessive or atomic?
by LanX (Saint) on Aug 16, 2015 at 20:00 UTC
    > but friend wrote to me, that with perl 5.20 he gained something wrong (warning/error).

    Couldn't you make this clear from the beginning?

    > don't have access to code,

    Then please reproduce it next time.

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!

      To by honest, I don't remember. And it is possible that I used that construct redundantly or I used it with wrong faith that after possessive quantifier succeeds then all backtrackings are disabled from this point (but for real backtrackings are disabled only in that group).
      Today I failed to imagine practical example where this atomic/possessive construct could be used.
      So I accessed today to the code.
      It was a regular expression which tries to match (number1) with (measuring units1){optional}, and (number2 with units2){optional}.
      The shortened for simplicity regex looks like that:
      /^ (?: ' \s* )? ($positive_number){1}+ \s* (?: \( \s* ($stdev) \s* \) )? \s* ($units_1)? ( \s* ($positive_number) \s* (?: \( \s* ($stdev) \s* \) )? \s* ($units_2) )? (?: \s* ' )? $/x
      For example: $units_1 = "A|B3"; $units_2 = "C|D-3"; Then regex should match:
      20B3 20 B3 15 D-3 20A15C
      but it shouldn't match 20C.
      With new backtracking it matches 20C as (2, undef, undef, 0, undef, C) === ($1, $2, $3, $4, $5, $6)
        Well the question seems answered now, its a bug from 5.20 onwards.

        (?>...) still works like expected (and its better readable IMHO)

        Seems like someone thought there should be a (erroneous) warning and patched the code.

        The perldoc mentioning redundancy might have paved the way for accepting this patch too easily.

        I'm surprised there was no unit test that alarmed p5p.

        Cheers Rolf
        (addicted to the Perl Programming Language and ☆☆☆☆ :)
        Je suis Charlie!