in reply to Testing for readdir failure
And I wouldn't be surprised if $! also holds some informations, i.e. would be set in case of failure.
Cheers Rolf
( addicted to the Perl Programming Language)
OK, I tested to read from a directory which was deleted in the meantime, with mixed results, sometimes the error was catched, but sometimes not ???
use strict; use warnings; $|=1; my $dh; sub tst { my $flag=shift; print "\n\n-----"; print "Provoking error\n" if $flag; mkdir "/tmp/bla"; sleep 1; opendir $dh, "/tmp/bla" or die "$!"; rmdir "/tmp/bla" if $flag; sleep 1; eval { print scalar readdir($dh); warn "--- $!" if $! and $! !~ /^File exists/; }; warn "--- $@" if $@; } tst($_) for 1,1,0,0;
consider also catching warnings with $SIG{__WARN__}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Testing for readdir failure
by Zzenmonk (Sexton) on Apr 24, 2013 at 08:43 UTC | |
by LanX (Saint) on Apr 24, 2013 at 10:39 UTC | |
by Zzenmonk (Sexton) on Apr 24, 2013 at 11:35 UTC | |
by Bob Cook (Acolyte) on Apr 24, 2013 at 17:04 UTC | |
by Zzenmonk (Sexton) on Apr 26, 2013 at 08:18 UTC |