Skip to content

Commit

Permalink
Add a work-around function for older Perls
Browse files Browse the repository at this point in the history
  • Loading branch information
scottchiefbaker committed Nov 29, 2023
1 parent bd69285 commit 6b00151
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pod/perlvar.pod
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,26 @@ information on this form and its uses.

This variable was added in 5.25.7

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

sub get_captures {
my $str = $&;
my @captures = ();

# Build array using the offsets from @- and @+
for (my $i = 1; $i < @-; $i++) {
my $start = $-[$i];
my $end = $+[$i];
my $len = $end - $start;

my $str = substr($str, $start, $len);
push(@captures, $str);
}

return @captures;
}

=item $MATCH

=item $&
Expand Down

0 comments on commit 6b00151

Please sign in to comment.