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.
Why is it not getting input when I use <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.
Why is it not getting input when I use <stdin>
?
Didn't know about this, but found it documented in a throw-away paragraph in
perlop
STDIN
is the documented filehandle. There existsstdin
as well, which is aliased toSTDIN
, but it only works in themain::
package:main::stdin
is the same asmain::STDIN
(as documented in perlop - Perl operators and precedence).In a package, therefore,
stdin
is interpreted asMy::Package::stdin
, which doesn't exist. You can usemain::stdin
from a package, but using the standardSTDIN
(which always points tomain::STDIN
, even from a package) is much cleaner.