< stdin>和有什么区别?和< STDIN> ;? [英] What is the difference between <stdin> and <STDIN>?
问题描述
当我在Perl模块(*.pm
)文件中使用<stdin>
时,它不是从键盘读取输入,但是当我在同一位置使用<STDIN>
时,它可以正常工作.
When I use <stdin>
in Perl module (*.pm
) files it's not reading input from the keyboard, but when I use <STDIN>
in the same place it works fine.
为什么我使用<stdin>
时没有得到输入?
Why is it not getting input when I use <stdin>
?
推荐答案
STDIN
是已记录的文件句柄.也存在stdin
,别名为STDIN
,但仅在main::
程序包中起作用:main::stdin
与main::STDIN
相同(如perlop-Perl运算符和优先级).
STDIN
is the documented filehandle. There exists stdin
as well, which is aliased to STDIN
, but it only works in the main::
package: main::stdin
is the same as main::STDIN
(as documented in perlop - Perl operators and precedence).
因此,在包装中,
package My::Package;
sub xx {
print while <stdin>;
}
stdin
被解释为My::Package::stdin
,它不存在.您可以从包装中使用main::stdin
,但是使用标准的STDIN
(即使从包装中也始终指向main::STDIN
)会更干净.
stdin
is interpreted as My::Package::stdin
, which doesn't exist. You can use main::stdin
from a package, but using the standard STDIN
(which always points to main::STDIN
, even from a package) is much cleaner.
这篇关于< stdin>和有什么区别?和< STDIN> ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!