siegfr...@heintze.com wrote:
I apologize if this appears twice. Since I sent it once and forgot to
abandon HTML in favor of plain text, I'm sending it again.
This works:
$ perl -e ' $s = <STDIN> ; print "$s\n"; '
I don't like it because <STDIN> is hard coded. What if I want to
conditionally read from a file?
Here is my attempt to store it in a variable but it does not work with
ActiveState Perl:
$ perl -e ' local X; X = <STDIN> ; $s = X ; print "$s\n"; '
Can't modify constant item in local at -e line 1, near "X;"
The statement:
local X;
is wrong because local() only works with variables like $X, @X, %X, &X
or *X. A bareword like X is seen by Perl as either a constant or a
string, unless it has been properly opened by open() or opendir().
Execution of -e aborted due to compilation errors.
What is the syntax? Is <STDIN> a file handle in perl?
<STDIN>
is short for:
readline STDIN
The bareword STDIN is a filehandle, if it has been opened correctly,
which Perl does for you when the program starts, and the <> operator is
a short form of the readline operator.
John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction. -- Albert Einstein
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/