Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: Testing for readdir failure

by eye (Chaplain)
on Apr 21, 2013 at 12:14 UTC ( [id://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.

Replies are listed 'Best First'.
Re^3: Testing for readdir failure
by LanX (Saint) 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 (Canon) 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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1029756]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-20 01:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found