"M. Kristall" schreef:
> John W. Krahn:
>> Chad Perrin:
>>> John W. Krahn:
>>>> print/.*/g,$"while<>
>
> Yeah, that's it.
>>> Woah, that's pretty short.
>>
>> 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))
With while(), the $_ is already local. Wouldn't using that 'local'
explicitly, add another local-layer?
> for (<>) is the same as for (readline (ARGV))
ITYM: readline(*ARGV)
See also:
perldoc -f readline
perldoc perlop (look for "I/O operators")
$ perl -MO=Deparse -e 'readline(ARGV)'
readline 'ARGV';
$ perl -MO=Deparse -e 'readline(*ARGV)'
<ARGV>;
$ perl -MO=Deparse -e 'while (<>) {}'
while (defined($_ = <ARGV>)) {
();
}
$ perl -MO=Deparse -e 'for (<>) {}'
foreach $_ (<ARGV>) {
();
}
--
Affijn, Ruud
"Gewoon is een tijger."
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>