I can answer your question on two grounds, neither of which refer to the source code. Both are pretty easy:

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.