On Thu Jun 27 15:17:07 2013, felipe@felipegasper.com wrote: > readdir() should not set $! on the first empty read when there's no > actual OS error; otherwise, it's impossible to check for errors. > > The below will not print anything, which allows for due error checking > on the <$dh>: > > =========== > > perl -MFile::Temp -E'my $node = File::Temp::tempfile(); open my $h, > "<", $node or die $!; local $!; 1 while <$dh>; print $!' > =========== That line has a bug -Mstrict would have caught ;-) > The following, though, prints an error: > > =========== > > perl -MFile::Temp -E'my $dir = File::Temp::tempdir( CLEANUP => 1 ); > opendir my $dh, $dir or die $!; local $!; 1 while readdir $dh; > print $!' > Bad file descriptor > =========== > > ...which makes it impossible to rely on error-checking on the > readdir() since > there is always an error at the normal end of iterating through the > directory. You're correct, it explicitly sets errno to EBADF if it doesn't already have a value. Quite frankly, I'm not seeing the point of it either. It's dating back to perl 4.0 patch 14 from 1991, a 1200 line patch that does contain "certain perl errors should set EBADF so that $! looks better", but I think in case of readdir it's an accident of implementation. > There's no error set if readdir() is called in list context; however, > this has > memory complications if the directory is large. Indeed. Leon --- via perlbug: queue: perl5 status: open https://rt.perl.org:443/rt3/Ticket/Display.html?id=118651Thread Next