Skip to content

Commit

Permalink
Perlvar: Add documentation for alternative to ${^CAPTURE}
Browse files Browse the repository at this point in the history
  • Loading branch information
scottchiefbaker committed Dec 22, 2023
1 parent 2ae2f22 commit 61db135
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions pod/perlvar.pod
Original file line number Diff line number Diff line change
Expand Up @@ -1096,8 +1096,8 @@ An array which exposes the contents of the capture buffers, if any, of
the last successful pattern match, not counting patterns matched
in nested blocks that have been exited already.

Note that the 0 index of @{^CAPTURE} is equivalent to $1, the 1 index
is equivalent to $2, etc.
Note that the 0 index of C<@{^CAPTURE}> is equivalent to C<$1>, the 1 index
is equivalent to C<$2>, etc.

if ("foal"=~/(.)(.)(.)(.)/) {
print join "-", @{^CAPTURE};
Expand All @@ -1120,6 +1120,19 @@ information on this form and its uses.

This variable was added in 5.25.7

If you need access to this functionality in older Perls you can use this
function immediately after your regexp.

sub get_captures {
no strict 'refs';

my $last_idx = scalar(@-) - 1;
my @arr = 1 .. $last_idx;
my @ret = map { $$_; } @arr;

return @ret;
}

=item $MATCH

=item $&
Expand Down

0 comments on commit 61db135

Please sign in to comment.