我尝试了以下两个脚本。脚本 1 得到了我预期的结果。脚本 2 没有 - 可能卡在 while 循环中?
$_= "Now we are engaged in a great civil war; we will be testing whether
that nation or any nation so conceived and so dedicated can long endure. ";
my $count = 0;
while (/we/ig){
$count++
};
print $count;
输出2
$_= "Now we are engaged in a great civil war, we will be testing whether
that nation or any nation so conceived and so dedicated can long endure";
my $count = 0;
while (/we/){
$count++
};
print $count;
我的理解是/g
允许全局匹配。但是我只是对脚本 2 很好奇,在 Perl 找到第一个匹配 "we"$_
并且$count
现在等于 1 之后,当它循环返回时,由于没有/g
,它如何响应?还是因为不知道如何响应而卡住了?