M
Mike Mimic
Hi!
I think that I found some inconsistency in Perl.
Let us suppose we have a file named "file.txt" that contains
only one byte which is '0' (ASCII character for number 0).
And we execute this code:
open(FILE, '<file.txt');
if (<FILE>) {
print "OK\n";
}
close(FILE);
And code does not output anything. What is correct as "0" is
false in Perl.
But then we try this:
open(FILE, '<file.txt');
while (<FILE>) {
print "OK\n";
}
close(FILE);
And code do output "OK". What is strange. Becasue "0" is still
false. In "Programming Perl" it is written:
The while statement repeatedly executes the block as long as EXPR is true.
But "0" is false.
So what is going on?
Mike
I think that I found some inconsistency in Perl.
Let us suppose we have a file named "file.txt" that contains
only one byte which is '0' (ASCII character for number 0).
And we execute this code:
open(FILE, '<file.txt');
if (<FILE>) {
print "OK\n";
}
close(FILE);
And code does not output anything. What is correct as "0" is
false in Perl.
But then we try this:
open(FILE, '<file.txt');
while (<FILE>) {
print "OK\n";
}
close(FILE);
And code do output "OK". What is strange. Becasue "0" is still
false. In "Programming Perl" it is written:
The while statement repeatedly executes the block as long as EXPR is true.
But "0" is false.
So what is going on?
Mike