Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Complete Directory+Depth Listing

by RhetTbull (Curate)
on Jul 11, 2001 at 22:50 UTC ( [id://95807]=note: print w/replies, xml ) Need Help??


in reply to Complete Directory+Depth Listing

I tried your script and it seems to produce nice output however it's possible to break it. In sub learn files:
my $file_info = stat($File::Find::name); $dirs{$File::Find::dir}{size} += $file_info->size;
you don't check the return status of stat. If $File::Find::name is a broken link, stat may fail (it does on my system) and you get the following error:
Can't call method "size" on an undefined value at ./files.pl line 50.
As a general rule of thumb, you should always check the return value of things that might fail (which includes almost any call related to the file system). It might also be possible to break this with a race condition where $File::Find::name was deleted prior to the stat.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2024-04-19 01:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found