【发布时间】:2020-03-29 07:57:48
【问题描述】:
我正在尝试遵循一段代码。基本上,根据我的理解,这段代码不应该改变 $data 。我错过了什么吗?我正在使用 5.22.3(草莓 perl)。
use strict;
use warnings;
use 5.010;
my $data = 'we are here';
$data =~ s///g;
print "DATA1: $data\n";
$data =~ s{(we)}{
my $x1 = $1;
$x1 =~ s///g;
print "x1: ^^$x1^^\n";
"$x1"
}e;
print "DATA2: $data\n";
O/P-
DATA1: we are here
x1: ^^^^
DATA2: are here
【问题讨论】:
-
对我来说似乎是一个错误。
$x1 =~ s///g;正在删除$x1中的所有内容,而不是删除任何内容(应该如此)。 -
与 5.28.2 草莓 perl 相同的问题
标签: regex perl substitution