Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://137871]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (11)
As of 2016-12-09 13:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (151 votes). Check out past polls.