Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^3: opendir slower than ls on large dirs?

by gellyfish (Monsignor)
on Jul 05, 2005 at 10:28 UTC ( [id://472403]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2024-03-28 19:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found