http://qs321.pair.com?node_id=137871


in reply to Working through directories

Although perl normally makes things pretty for the programmer, file listings aren't kept by the OS in any particular sort order. To sort it would require extra processing, and a lot of users of readdir don't care if it's sorted or not, or even don't want to read all of a directory listing, so it makes sense for perl not to do the extra work by default.

If you'd structured your code to read the dir into an array, and then work through that array doing work on each entry, then it'd be trivial to sort the list items however you want. Also, it'd allow you to deal with any errors reading the dir more flexibly (should you want to produce no output, or a specific error if their is a problem with readdir()) This is generally a good programming practice if you want to reuse code, or want to change where a program sources its data from.

the hatter