- 论坛徽章:
- 145
|
你说的应该没错....
加入print实验结果为....
$x =~ /(?{local $c = 0;}) # initialize count
( a # match 'a'
(?{local $c=$c+1; print "a($c),";}) # increment count
)* # do this any number of times,
aa # but match 'aa' at the end
(?{print "aa($c)\n";$count = $c;}) # copy local $c var into $count
/x;
#1. 有local
$ perl re_code.pl
a(1),a(2),a(3),a(4),aa(2)
'a' count is 2, $c variable is 'bob'
#2. 没有local, a*由aaaa回溯为aa,但$c还是等于4(只有一个$c)
$ perl re_code.pl
a(1),a(2),a(3),a(4),aa(4)
'a' count is 4, $c variable is 'bob' |
|