in reply to opendir slower than ls on large dirs?

my $file = 'somefile*'; ... my (@files) = (grep (/$file/, readdir(F)));
I'm not exactly sure how it flaws your benchmark, but that's definitely not going to do what you intend it to do. You're looking for any filename that contains "somefil" followed by zero or more letter e. Do you want that, or do you instead want: /^somefile/?

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

Replies are listed 'Best First'.
Re^2: opendir slower than ls on large dirs?
by Anonymous Monk on Jul 06, 2005 at 14:22 UTC
    heh, you're right in that i want /^somefile/ not somefile*. Is glob the fastest way to find files in a directory? The opendir, grep ... readdir did I take from "perldoc -f readdir" and it seemed like a nice sollution, but I'm skipping it for glob. What I was trying to figure out in the first place was "what's the cheapest way of listing a bunch of files in a directory" and it seems to me like glob is the way to go. Thanks everyone for all the answers