Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: quickest way to find number of files in a directory?

by jdporter (Paladin)
on Mar 27, 2007 at 20:05 UTC ( [id://606862]=note: print w/replies, xml ) Need Help??


in reply to Re: quickest way to find number of files in a directory?
in thread quickest way to find number of files in a directory?

++ to you. That's the way to go.

I like let handles close automatically on block exit (where feasible) and since this snippet fits naturally in a sub, I'd do this:

sub files_in_dir { my $dir = shift || '.'; opendir my $dh, $dir or croak "opendir '$dir' - $!"; grep { -f } readdir $dh; }

It produces the number of files if called in scalar context and the list of filenames if called in list context.

A word spoken in Mind will reach its own level, in the objective world, by its own weight

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2024-04-18 20:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found