Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Working through directories

by hatter (Pilgrim)
on Jan 11, 2002 at 03:59 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://137871]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-19 23:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found