Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^2: Testing for readdir failure

by eye (Chaplain)
on Apr 21, 2013 at 12:14 UTC ( #1029756=note: print w/ replies, xml ) Need Help??


in reply to Re: Testing for readdir failure
in thread Testing for readdir failure

From the documentation, it is not clear that readdir returns an error in $!.

Another approach would be to stat the directory and verify that the link count matches the number of file names returned. That seems likely to catch an error, though not to identify the cause.


Comment on Re^2: Testing for readdir failure
Re^3: Testing for readdir failure
by LanX (Canon) on Apr 21, 2013 at 12:16 UTC
    > From the documentation, it is not clear that readdir returns an error in $!.

    Worse! in my tests it returns sometimes "File exists" if there's no error.

    see Testing for readdir failure

    Cheers Rolf

    ( addicted to the Perl Programming Language)

Re^3: Testing for readdir failure
by Laurent_R (Vicar) on Apr 21, 2013 at 14:54 UTC

    Well it does seem to populate $! in at least some cases. I have an empty directory called "foo":

    $ perl -e 'opendir DIR, "foo" or die "$!"; @c=readdir DIR; print "@c\n +"; closedir DIR; @c=readdir DIR or die "$!"' . .. Bad file descriptor at -e line 1.

    I also got the following $! error in my quick tests under the debugger:

    DB<8> @c = readdir DIR or die "$!" Illegal seek at (eval 12)[/usr/lib/perl5/5.10/perl5db.pl:638] line 2.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1029756]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (21)
As of 2014-07-11 18:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (235 votes), past polls