< stdin>和有什么区别?和< STDIN&gt ;? [英] What is the difference between <stdin> and <STDIN>?

查看:80
本文介绍了< stdin>和有什么区别?和< STDIN&gt ;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在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::stdinmain::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.

这篇关于&lt; stdin&gt;和有什么区别?和&lt; STDIN&gt ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆