|
发表于 2004-6-10 10:43:31
|
显示全部楼层
解决了:
- #!/usr/bin/perl -w
- use strict;
- my $np;
- $np = qr[\{(?:(?>[^{}]+)|(??{$np}))*\}];
- my $abcnp = qr/abc($np)/;
- print "Please input the string: ";
- my $text = <stdin>;
- if ($text =~ /^$abcnp/) {
- print "Result is $1\n";
- } elsif ($text =~ /^abc(\{.*?\})/){
- print "Result is $1\n";
- } else {
- print "No result!\n";
- }
复制代码
这个问题可以参考骆驼书中文版的245页。不过那一页上至少有3处印刷错误,大家也要注意了。 |
|