On Sun, 2006-23-04 at 05:03 -0400, M. Kristall wrote:
> John W. Krahn wrote:
> > You can make it even shorter:
> > 
> > print/.*/g,$"for<>
> They aren't quite the same though. 'while' loops if the condition is 
> still true (scalar context). 'for' loops if there are more items in the 
> array (array context).
> 
> while (<>) gets a little extra magic than just the normal <>.
> while (<>) is the same as while (local $_ = readline (ARGV))
> for (<>) is the same as for (readline (ARGV))
> 

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. The
expression 'while(<>)' is in scalar context. It reads the file one line
at a time.


-- 
__END__

Just my 0.00000002 million dollars worth,
   --- Shawn

"For the things we have to learn before we can do them, we learn by doing them."
  Aristotle

* Perl tutorials at http://perlmonks.org/?node=Tutorials
* A searchable perldoc is at http://perldoc.perl.org/



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