in reply to Re^2: opendir slower than ls on large dirs?
in thread opendir slower than ls on large dirs?

Er, no because an intermediate list is still being built. I think the fairer comparison would be to assign to an array in the foo subroutine.

Of course a readdir and a grep is not at all equivalent to ls <file> which will immediately see that $file exists (or not) and will not do any further searching, in the pure perl code you are going through every directory entry irrespective of whether you have seen the file or not. You will see somewhat similar performance hit if you did `ls $dir | grep $file`

/J\

Replies are listed 'Best First'.
Re^4: opendir slower than ls on large dirs?
by Anonymous Monk on Jul 05, 2005 at 13:02 UTC
    Well ok, it's not the exact thing but my original point was more "how the hell can it be so damn slow". When you look at perldoc -f readdir the grep sollution is what's suggested, eventhough it seems like a really bad idea.

    A little mention of glob would be nice as it does the exact same thing but a hundred times quicker or so.