Perldoc Search: "@+" perl-5.20.1

search official POD

6 PODs, 13 LINEs found.
406 :     In Perl 5.6.0 the "@-" and "@+" dynamic arrays were introduced that supply the indices of successful matches. So you could for example do this:
527 :     @+      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 *n*th element of this array holds the offset of the *n*th 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.
532 :     %+      Similar to "@+", the "%+" hash allows access to the named capture buffers, should they exist, in the last successful match in the currently active dynamic scope.
551 :             Thus, after a match against $_, $& coincides with "substr $_, $-[0], $+[0] - $-[0]". Similarly, $*n* coincides with "substr $_, $-[n], $+[n] - $-[n]" if $-[n] is defined, and $+ coincides 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 "@+".
406 :                                          (@+) */
414 :             I32 subcoffset; /* suboffset equiv, but in chars (for @-/@+) */
501 :     In the presence of the "REXEC_COPY_STR" flag, but with the addition of the "REXEC_COPY_SKIP_PRE" or "REXEC_COPY_SKIP_POST" flags, an engine can choose not to copy the full buffer (although it must still do so in the presence of "RXf_PMf_KEEPCOPY" or the relevant bits being set in "PL_sawampersand"). In this case, it may set "suboffset" to indicate the number of bytes from the logical start of the buffer to the physical start (i.e. "subbeg"). It should also set "subcoffset", the number of characters in the offset. The latter is needed to support "@-" and "@+" which work in characters, not bytes.
470 :     In addition to what was matched, Perl also provides the positions of what was matched as contents of the "@-" and "@+" arrays. $-[0] is the position of the start of the entire match and $+[0] is the position of the end. Similarly, $-[n] is the position of the start of the $n match and $+[n] is the position of the end. If $n is undefined, so are $-[n] and $+[n]. Then this code
491 :     If your code is to run on Perl versions earlier than 5.20, it is worthwhile to note that using $` and $' slows down regexp matching quite a bit, while $& slows it down to a lesser extent, because if they are used in one regexp in a program, they are generated for *all* regexps in the program. So if raw performance is a goal of your application, they should be avoided. If you need to extract the corresponding substrings, use "@-" and "@+" instead:
930 :     Interpolating an array or slice interpolates the elements in order, separated by the value of $", so is equivalent to interpolating "join $", @array". "Punctuation" arrays such as "@*" are usually interpolated only if the name is enclosed in braces "@{*}", but the arrays @_, "@+", and "@-" are interpolated even without braces.
1632 :             Interpolation in patterns has several quirks: $|, $(, $), "@+" and "@-" are not interpolated, and constructs $var[SOMETHING] are voted (by several different estimators) to be either an array element or $var followed by an RE alternative. This is where the notation "${arr[$bar]}" comes handy: "/${arr[0-9]}/" is interpreted as array element -9, not as a regular expression from the variable $arr followed by a digit, which would be the interpretation of "/$arr[0-9]/". Since voting among different estimators may occur, the result is not predictable.
760 :                                                  (@+ and @- vars)
256 :        @+    Offsets of ends of groups. $+[0] holds end of whole match
<< Back to Perldoc Search