The first is that Perl runs on more than 30 OSs. For perl to guarantee an order, it would have to sort the file names before returining them to me. How annoyed would I be if I opened a directory with 15,000 files in it and perl paused for 5 seconds while it sorted the list. And how should it sort it? I would be doubly annoyed if it sorted it by name and I wanted it by date.
The second reason calls on laziness: the perl programmers aren't going to waste any precious braintime programming a directory read function if there is another one available. And there is one supplied by the OS in Unix, it's a system function called readdir(). The way to get a system directory handle is with opendir(). There's a pattern here... the perl programmers just pass the call straight through to the OS. Reading the manual for Solaris, I see that it goes out of it's way to avoid mentioning sort order for files in a directory. The reason for this is that you could have over five different types of file system, each returning file lists in a different order(by date, by size, by last accessed, by weird b-tree sort, etc.). How pissed off would we be if Solaris paused for five seconds every time we opened a directory with 15,000 files in it?
Substitute Linux for Solaris above and you have the same story, except you could have maybe 20 filesystems returning files in different orders.
____________________
Jeremy
I didn't believe in evil until I dated it.
In reply to Re: What order do my files come from readdir() in?
by jepri
in thread What order do my files come from readdir() in?
by Cody Pendant
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |