【发布时间】:2012-10-29 21:44:14
【问题描述】:
考虑这个简单的程序。你能解释一下为什么取消前两行的注释后输出不同吗?我的 use strict 哈希发生了什么?如何修复程序以使用use strict?
echo -e "key1\nkey2\nkey3" | perl -lne '
#use strict; use warnings;
#my %hash;
BEGIN {
$hash{'key3'} = "value";
}
chomp;
if ($hash{$_}) {
print "$_ matched";
} else {
print "$_ unmatched ";
}
'
输出:
key1 unmatched
key2 unmatched
key3 matched
【问题讨论】:
标签: perl