如何使用量词访问括号中的捕获缓冲区?
#!/usr/local/bin/perl
use warnings;
use 5.014;
my $string = '12 34 56 78 90';
say $string =~ s/(?:(\S+)\s){2}/$1,$2,/r;
# Use of uninitialized value $2 in concatenation (.) or string at ./so.pl line 7.
# 34,,56 78 90
使用@LAST_MATCH_START
并且@LAST_MATCH_END
它可以工作*,但是行变得太长。不行,看TLP的回答。
*The proof of the pudding is in the eating
并不总是正确的。
say $string =~ s/(?:(\S+)\s){2}/substr( $string, $-[0], length($-[0]-$+[0]) ) . ',' . substr( $string, $-[1], length($-[1]-$+[1]) ) . ','/re;
# 12,34,56 78 90