我不认为以下应该工作,但它确实:
$ perl -e '@a = qw/1222 2 3/; while (<@a>) { print $_ ."\n";}'
1222
2
3
$
据我所知,Perl 的
<>
操作符应该处理文件句柄、globs 等,除了文字 <>
(而不是 <FILEHANDLE>
),它神奇地迭代了 @ARGV
.有谁知道它是否也应该像我的测试一样工作?
最佳答案
魔法在工作!
来自' perldoc perlop ':
If what's within the angle brackets is neither a filehandle nor a simple scalar variable containing a filehandle name, typeglob, or typeglob reference, it is interpreted as a filename pattern to be globbed, and either a list of filenames or the next filename in the list is returned, depending on context.
这是您使用此代码触发的规则。这是发生了什么:
关于perl - Perl 菱形运算符是否迭代非魔法数组(不是@ARGV)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1640724/