Perldoc Search: "$^N" perl-5.20.1

search official POD


5 PODs, 11 LINEs found.
perlretut.pod
397 :     For convenience, Perl sets $+ to the string held by the highest numbered $1, $2,... that got assigned (and, somewhat related, $^N to the value of the $1, $2,... most-recently assigned; i.e. the $1, $2,... associated with the rightmost closing parenthesis used in the match).
1483 :                            (?{ $z0 = $z1; $z1 .= $^N; })
1489 :     Remember that $^N is set to whatever was matched by the last completed capture group. This prints
1500 :         /^1(?:((??{ $z0 }))1(?{ $z0 = $z1; $z1 .= $^N; }))+$/
perlre.pod
447 :     Several special variables also refer back to portions of the previous match. $+ returns whatever the last bracket match matched. $& returns the entire matched string. (At one point $0 did also, but now it returns the name of the program.) $` returns everything before the matched string. $' returns everything after the matched string. And $^N contains whatever was matched by the most-recently closed group (submatch). $^N can be used in extended patterns (see below), for example to assign a submatch to a variable.
716 :         Note that the special variable $^N is particularly useful with code blocks to capture the results of submatches in variables without having to keep track of the number of nested parentheses. For example:
719 :           /the (\S+)(?{ $color = $^N }) (\S+)(?{ $animal = $^N })/i;
perlvar.pod
514 :     $^N     The text matched by the used group most-recently closed (i.e. the group with the rightmost closing parenthesis) of the last successful search pattern.
518 :                 (?:(...)(?{ $var = $^N }))
perlreapi.pod
403 :             U32 lastcloseparen;       /* last close paren matched ($^N) */
perlreref.pod
253 :        $^N   Holds the most recently closed capture
<< Back to Perldoc Search