in reply to Testing for readdir failure
Maybe you could just try this:
my @x; if ( opendir(my $DIR, $somedir) ) { @x = readdir($DIR) or die "$!"; closedir($DIR); }
At least, it would give you a diagnostic if the readdir instruction fails.
Also using the strict and warnings pragmas might help if you don't (and you should do it).
A possible alternative would be to use the glob function, which is often more practical than the opendir/readdir combination. Perhaps something like this:
my @x = glob "$somedir/*.*" if -d $somedir;would do the trick.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Testing for readdir failure
by eye (Chaplain) on Apr 21, 2013 at 12:14 UTC | |
by LanX (Saint) on Apr 21, 2013 at 12:16 UTC | |
by Laurent_R (Canon) on Apr 21, 2013 at 14:54 UTC |