Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Re: Re: What's like $+ but not gives the ordinal?

by japhy (Canon)
on Jun 28, 2001 at 03:33 UTC ( [id://92121]=note: print w/replies, xml ) Need Help??


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

This appears to be a bug. perlvar says that $#+ should return the number of successful groupings, but it doesn't -- it returns the number of attempted groupings. $#-, on the other hand, works as expected.

japhy -- Perl and Regex Hacker
  • Comment on Re: Re: Re: What's like $+ but not gives the ordinal?

Replies are listed 'Best First'.
Re: Re: Re: Re: What's like $+ but not gives the ordinal?
by John M. Dlugosz (Monsignor) on Jun 28, 2001 at 18:49 UTC
    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

      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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://92121]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-04-19 02:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found