当我运行这段代码,我得到“没有”打印出来:的Perl写一个“内存文件”玩技巧与模式匹配
my $memory_file;
my $fh;
open ($fh, '>', \$memory_file);
print $fh "abc";
if($memory_file =~ m/^.*$/)
{ print "yes\n" }
else
{ print "no\n" }
如果我打印出来$memory_file
,内容确实是。
如果我将模式更改为.*
(否^
或$
),它按预期工作。
如果在比赛开始前我把$memory_file = "abc"
放在了一行,我会打印出“yes”(正如原来的预期)。
这到底是怎么回事?
(这是Perl的5.14.1)
更新:上PerlMonks一些更多的讨论。它看起来像一个错误,我会记录它。
更新2:精细Perl开发人员有固定的这个错误:https://rt.perl.org/rt3//Public/Bug/Display.html?id=108398
这看起来像一个bug:http://perldoc.perl.org/perlbug.html('perldoc perlbug') – toolic 2011-12-28 01:52:13