Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between <stdin> and <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>?

like image 238
Rajalakshmi Avatar asked Jul 02 '15 13:07

Rajalakshmi


1 Answers

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).

In a package, therefore,

package My::Package;
sub xx {
    print while <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.

like image 108
choroba Avatar answered Oct 06 '22 11:10

choroba