Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Working through directories

by hatter (Pilgrim)
on Jan 11, 2002 at 03:59 UTC ( #137871=note: print w/ replies, xml ) Need Help??


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


Comment on Re: Working through directories
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2014-09-03 03:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (35 votes), past polls