- 论坛徽章:
- 0
|
原帖由 HorseJia 于 2008-3-31 20:04 发表 ![]()
示例一:
$_ = 'a2b';
/a(??{if($' eq '2b') {'2'}}/;
示例二:
$_ = 'a2b';
/a(??{if($' =~ m#2b#) {'2'}}/;
其中示例一,匹配成功;示例二,匹配不成功。
我想问的是,这意味着动态表达式的条件中 ...
很神奇
难道是个bug??
debug了一下
- #!/usr/bin/perl
- use re qw ( debug );
- use strict;
- use warnings;
- $_ = "a2b";
- #print "Matched at $& \n" if /a(?{ print "Goes here \n" if $' eq "2b" ;})/;
- print "Matched $& \n" if m@a(?(?{ $' =~ /2b/ })2)@;
复制代码EXECUTING...
Guessing start of match, REx `a(?(?{ $' =~ /2b/ })2)' against `a2b'...
Found anchored substr `a' at offset 0...
Guessed: match at offset 0
Matching REx `a(?(?{ $' =~ /2b/ })2)' against `a2b'
Setting an EVAL scope, savestack=12
0 <> <a2b> | 1: EXACT <a>
1 <a> <2b> | 3: LOGICAL[1]
1 <a> <2b> | 4: EVAL
re_eval 0x8080318
Guessing start of match, REx `2b' against `2b'...
Found anchored substr `2b' at offset 0...
Guessed: match at offset 0
Matching REx `2b' against `2b'
Setting an EVAL scope, savestack=12
0 <> <2b> | 1: EXACT <2b>
2 <2b> <> | 3: END
Match successful!
-89031 <> <2b> |15280:IFTHEN
-89031 <> <2b> |15282:EXACT <2>
-89030 <> <b> |15287:END
Match possible, but length=-89030 is smaller than requested=0, failing!
Match failed
Freeing REx: `"a(?(?{ $' =~ /2b/ })2)"'
Freeing REx: `"2b"'
ms是match的,后来堆栈返回的时候出错了 |
|