--- Bob Mangold <[EMAIL PROTECTED]> wrote:
> I'm having trouble reading STDIN.
>
> This works:
>
> $a = readline STDIN;
> print $a; # prints out whatever was inputed
>
> But the does not work:
>
> use strict;
> $a = readline <STDIN>; # forced to use <STDIN>
> print $a; # prints nothing
This reads a line from the standard input with the <> operator, which
does the same thing as readline; then readline tries to read a line
from the typeglob returned from reading a line from STDIN. You're
double reading.
Either add an asterisk in front of STDIN to make strict recognize it as
a typeglob, like this:
$a = readline *STDIN;
or *just* use the <>, like this:
$a = <STDIN>;
>From perldoc -f readline:
readline EXPR
Reads from the filehandle whose typeglob is contained in EXPR.
In scalar context, each call reads and returns the next
line, until end-of-file is reached, whereupon the subsequent
call returns undef. In list context, reads until end-of-file is
reached and returns a list of lines. Note that the notion
of ``line'' used here is however you may have defined it with $/
or $INPUT_RECORD_SEPARATOR). See perlvar/``$/''.
When $/ is set to undef, when readline() is in scalar context
(i.e. file slurp mode), and when an empty file is read, it
returns '' the first time, followed by undef subsequently.
This is the internal function implementing the <EXPR> operator,
but you can use it directly. The <EXPR> operator is
discussed in more detail in perlop/``I/O Operators''.
$line = <STDIN>;
$line = readline(*STDIN); # same thing
Enjoy. =o)
=====
print "Just another Perl Hacker\n"; # edited for readability =o)
=============================================================
Real friends are those whom, when you inconvenience them, are bothered less by it than
you are. -- me. =o)
=============================================================
"There are trivial truths and there are great Truths.
The opposite of a trival truth is obviously false.
The opposite of a great Truth is also true." -- Neils Bohr
__________________________________________________
Do You Yahoo!?
Spot the hottest trends in music, movies, and more.
http://buzz.yahoo.com/