|
[text/plain 897b]
I need to include test cases for my own thoughts :).
The problem is in the while loop condition check, the return scalar
value of the IO::Dir->read (readdir). The code exits before Path::Class
has a chance to stringify it.
The while loop receives a scalar value from $handle (IO::Dir), which in
the case of a file or directory that is a name of "0" (zero) it
evaluates to false and the loop is terminated.
I've included a test case below:
use Path::Class;
use Path::Class::Dir;
mkdir '1';
mkdir '0';
my $dir=dir('.');
my $handle = $dir->open;
# while ( defined ( my $file = $handle->read ) ) { # this works.
while ( my $file = $handle->read ) { # IO::Dir->read returns a scalar value
print "1: ", $file, "\n";
$file = $dir->file($file); # Turn $file into Path::Class::File object
print "2: ", $file, "\n";
print "\n";
}
# clean up after ourself.
rmdir '1';
rmdir '0';
|