in reply to Re: Re: Re: What's like $+ but not gives the ordinal?
in thread What's like $+ but not gives the ordinal?

My copy reads,
@LAST_MATCH_END
@+


This array holds the offsets of the ends of the last successful submatches in the currently active dynamic scope. $+[0] is the offset into the string of the end of the entire match. This is the same value as what the pos function returns when called on the variable that was matched against. The nth element of this array holds the offset of the nth submatch, so $+[1] is the offset past where $1 ends, $+[2] the offset past where $2 ends, and so on. You can use $#+ to determine how many subgroups were in the last successful match. See the examples given for the @- variable.
It doesn't say that it tells you how many capturing parens were successful—rather, how many sets of capturing parens were present in the last successful match. That's consistant with its observed behavior.

The docs for @- says that the array element will be undef if the capture paren did not match, which is not claiming that trailing undef entries are deleted from the array.

I'd rather have a clear way to ask for either value than to use sideband information like this.

—John

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: What's like $+ but not gives the ordinal?
by japhy (Canon) on Jun 28, 2001 at 19:05 UTC
    Ah, I must have misread that as "sucessful subgroups were in the last match". Nevermind, then. The docs have this to say about @-:
    @- [snip] with `substr $_, $-[$#-], $+[$#-]'. One can use `$#-' to find the last matched subgroup in the last successful match. Contrast with `$#+', the number of subgroups in the regular expression. Compare with `@+'. [snip]


    japhy -- Perl and Regex Hacker
      Mine says “You can use $#- to determine how many subgroups were in the last successful match. Compare with the @+ variable.” which is basically the same as @+ and not at all what yours says. Yours matches what I'm seeing in the code.

      Perhaps the doc change didn't make it into the Release version when the code did, or ActiveState goofed in doing patches?

      —John

        Data points: my ActivePerl build 616 has japhy's wording as does my Indigo Perl 5.6.0 (and I recall this difference in the first Perl 5.6 that I installed which was probably ActivePerl build <616).

                - tye (but my friends call me "Tye")