由于在 Windows 上 *.csv 不会从命令行扩展到 @ARGV 我通常最终会做类似的事情
map { glob } @ARGV
获取文件名。
然而,我遇到了一个异常,只是想了解到底发生了什么。我刚刚读完“陌生土地上的陌生人”,所以我可以说我没有完全摸索!
use Modern::Perl;
# gets the filelist but then warns
say "Test 1 ", '-' x 20;
do { func($_) for map { glob } @ARGV } or warn "at least one arg expected\n";
say '-' x 27, "\n";
# works ok
say "Test 2 ", '-' x 20;
my @x = map { glob } @ARGV or warn "at least one arg expected\n";
func($_) for @x;
say '-' x 27, "\n";
# prints 2 (there are two files)
say "Test 3 ", '-' x 20;
func($_) for (map { glob } @ARGV or warn "at least one arg expected\n");
say '-' x 27, "\n";
sub func {
say "in func = $_[0]";
}
输出:
Test 1 --------------------
in func = t.csv
in func = t2.csv
at least one arg expected
---------------------------
Test 2 --------------------
in func = t.csv
in func = t2.csv
---------------------------
Test 3 --------------------
in func = 2
---------------------------
Test1:我不明白为什么do
没有真正返回,func
返回最后一个语句 is say
,如果有输出则返回 true 。或者是for
用作返回的那个do
?
测试3:显然标量上下文是隐含的,但如何?我在地图周围使用了括号?
谢谢,理查德。