With while(), the $_ is already local. Wouldn't using that 'local'
explicitly, add another local-layer?
my $i = 5;
$_ = 'Hi there!!!';
while ($_ = $i--) { print }
print
543210

my $i = 5;
$_ = 'Hi there!!!';
while (local $_ = $i--) { print }
print
54321Hi there!!!

for (<>) is the same as for (readline (ARGV))
ITYM: readline(*ARGV)
The readline doc says <STDIN> is the same as readline (*STDIN). True. It just so happens that readline (*STDIN) is the same as readline (STDIN). And all thanks to prototyping:

perl -Mstrict -e 'sub rlfe { <$_[0]> } rlfe (STDIN)'
perl -Mstrict -e 'sub rlfe (*) { <$_[0]> } rlfe (STDIN)'

The first will not compile. The second will run just as if your program were just
perl -e '<STDIN>'

Mr. Shawn H. Corey wrote:
> It's more than that. The expression 'for<>' is in array context. That
> means the entire file is read and stored the first time the expression
> in encountered. In other words, it does work for large files.
I guess I should have emphasized that 'while' works with anything that can evaluate to a true or false value and 'for' operates on lists.

John W. Krahn wrote:
> "array context"??  There is no "array context".
`perldoc -f wantarray`
"This function should have been named _wantlist()_ instead."
If they can do it, so can we ;-)

> local??  There is no local.
Hmm, never noticed that. I like mine better because I get to keep my initial $_ :-)

> while (<>) is the same as while (local $_ = readline (ARGV))
That really should have said while (defined (local $_ = readline (ARGV))), but I guess I was wrong about that anyway.

So while (<>) is _really_ while (defined ($_ = readline (ARGV))).
(This despite the fact that 'while ($_ = readline (ARGV))' continues looping even if $/ is 0.)

Dr.Ruud wrote:
> Rather one piece (or record) at a time, which by default is a line.
>
> The value of "$/" is the record separator
And 'readline' really should have been called 'getdelim' (`man 3 getdelim` - on GNU systems) or some such. But you're completely right.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to