See also: How is "0" result from readdir not false in a while condition?. (Not a duplicate; just closely related.)
Where in the documentation does it say that while tests readdir for definedness? For instance, this code
#!/usr/bin/perl
use strict;
use warnings;
opendir my $dir, "/tmp" or die "$!";
while (my $file = readdir($dir)) {
print "$file\n";
}
closedir $dir;
when run through B::Deparse yields:
use warnings;
use strict 'refs';
die "$!" unless opendir my $dir, '/tmp';
while (defined(my $file = readdir $dir)) {
do {
print "$file\n"
};
}
z.pl syntax OK
I expect this behaviour, but I cannot find where it is specified. In the I/O Operators section of perlop it says
The following lines are equivalent:
while (defined($_ = <STDIN>)) { print; }
while ($_ = <STDIN>) { print; }
while (<STDIN>) { print; }
for (;<STDIN>;) { print; }
print while defined($_ = <STDIN>);
print while ($_ = <STDIN>);
print while <STDIN>;
But there is no mention of readdir
.