Dr.Ruud wrote:
Jeff Peng wrote:

so how about while (my $line = <FILE>) instead of using $_?

Evil! An empty line, or a line with only a "0" in it.

Evil? "while (my $line = <FILE>)" is *exactly* the same as "while (defined(my $line = <FILE>))"

$ perl -e'
my $x = 1;
my $data = "one\ntwo\nthree\n0";
open FH, "<", \$data or die $!;

print "Loop: while ( \$x and my \$line = <FH> )\n";
while ( $x and my $line = <FH> ) {
    print $line;
    }
print "\n";

close FH;
open FH, "<", \$data or die $!;

print "Loop: while ( my \$line = <FH> )\n";
while ( my $line = <FH> ) {
    print $line;
    }
print "\n";
'
Loop: while ( $x and my $line = <FH> )
one
two
three

Loop: while ( my $line = <FH> )
one
two
three
0




John
--
The programmer is fighting against the two most
destructive forces in the universe: entropy and
human stupidity.               -- Damian Conway

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to