Search code examples
perlperlop

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};

Solution

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

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