Movatterモバイル変換


[0]ホーム

URL:


variables /@{^CAPTURE}
(source,CPAN)
You are viewing the version of this documentation from Perl 5.42.0-RC1. This is a development version of Perl.
#@{^CAPTURE}

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.

if ("foal"=~/(.)(.)(.)(.)/) {    print join "-", @{^CAPTURE};}

should output "f-o-a-l".

See also"$<digits> ($1, $2, ...)","%{^CAPTURE}" and"%{^CAPTURE_ALL}".

Note that unlike most other regex magic variables there is no single letter equivalent to@{^CAPTURE}. Also be aware that when interpolating subscripts of this array youmust use the demarcated variable form, for instance

print "${^CAPTURE[0]}"

see"Demarcated variable names using braces" in perldata for more 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;}

Perldoc Browser is maintained by Dan Book (DBOOK). Please contact him via theGitHub issue tracker oremail regarding any issues with the site itself, search, or rendering of documentation.

The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. Please contact them via thePerl issue tracker, themailing list, orIRC to report any issues with the contents or format of the documentation.


[8]ページ先頭

©2009-2025 Movatter.jp