$^N

$^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.

This is primarily used inside (?{...}) blocks for examining text recently matched. For example, to effectively capture text to a variable (in addition to $1 , $2 , etc.), replace (...) with

(?:(...)(?{ $var = $^N }))

By setting and then using $var in this way relieves you from having to worry about exactly which numbered set of parentheses they are.

This variable was added in Perl v5.8.0.

Mnemonic: the (possibly) Nested parenthesis that most recently closed.

doc_perl
2016-12-06 03:17:45
Comments
Leave a Comment

Please login to continue.