【发布时间】:2010-06-02 09:19:13
【问题描述】:
运行以下代码时,将打印 C:\Test 下面所有文件的文件名。为什么它不只打印Hello(n 次,取决于处理了多少文件)?
这是否意味着我不能依靠shift 可靠地分配给$_?想象一个同事实现了wtf 函数,但不知道它是从File::Find wanted 子调用的。
我用 Strawberry Perl 5.12 运行这段代码
编辑:此代码也没有按预期运行:
use strict;
use warnings;
wanted();
sub wanted{
wtf("Hello");
}
sub wtf {
shift;
print; #expecting Hello
}
所以我想我在这里完全不在高速公路上。这显然与 File::Find 无关,我现在正在为这个问题寻找一个新标题。这是我的原始代码:
use strict;
use warnings;
use File::Find;
find(\&wanted, "C:\\test");
sub wanted{
wtf("Hello");
}
sub wtf {
shift;
print; #expecting Hello
}
【问题讨论】:
-
试试 perldoc -f shift - 是什么让你认为 shift 分配给 $_?
-
我不知道。我只是想到了这两条线:换档;打印;
标签: perl find arguments implicit subroutine