Is there a name for the special variable% +?

I was wondering if there was an operator name for %+ , so instead of code like:

 /(?<CaptureName>\w+)/; ... my $whatever=$+{CaptureName}; 

I could use something more readable:

 use English; /(?<CaptureName>\w+)/; ... my $whatever=$?????{CaptureName}; 
+6
source share
3 answers

Using the English module, you can refer to it as %LAST_PAREN_MATCH :

 use English; /(?<CaptureName>\w+)/; ... my $whatever = $LAST_PAREN_MATCH{CaptureName}; 
+7
source

perldoc -v% +

  %LAST_PAREN_MATCH %+ 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. 
+6
source

You can refer to http://perldoc.perl.org/perlvar.html about the future for symbol names.

In your case, sylbe is called LAST_PAREN_MATCH

 %LAST_PAREN_MATCH %+ 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. 

For example, $ + {foo} is equivalent to $ 1 after the next

The only comment I would make is that the docs include the following:

 This variable was added in Perl v5.10.0. 

So, if you use an older interpreter, this can cause problems.

NOTE , since Keith points to the comment below, you can also use perldoc -v '$+' . This is only useful if the symbol is available in your installed version of Perl.

+6
source

All Articles