【发布时间】:2013-06-09 21:57:16
【问题描述】:
奇怪的是,反向引用 ($1,$2,$3) 在我的原始代码中不起作用,所以我从网络上运行了这个示例:
#!/usr/bin/perl
# matchtest2.plx
use warnings;
use strict;
$_ = '1: A silly sentence (495,a) *BUT* one which will be useful. silly (3)';
my $pattern = "silly";
if (/$pattern/) {
print "The text matches the pattern '$pattern'.\n";
print "\$1 is '$1'\n" if defined $1;
print "\$2 is '$2'\n" if defined $2;
print "\$3 is '$3'\n" if defined $3;
print "\$4 is '$4'\n" if defined $4;
print "\$5 is '$5'\n" if defined $5;
}
else {
print "'$pattern' was not found.\n";
}
这只是给了我:
The text matches the pattern 'silly'.
为什么找到模式后反向引用仍然未定义?我正在使用 Wubi(Ubuntu 12.04 64 位),我的 perl 版本是 5.14.2。提前感谢您的帮助。
【问题讨论】:
-
你期待什么输出?
-
你没有捕捉到模式,傻瓜。
-
@doubleDown 反正这种模式很傻。
-
大声笑,我 1 美元。谢谢
标签: perl undefined backreference