Main Content

Finding your big files in Perl - design considerations beyond the course environment

Archive - Originally posted on "The Horse's Mouth" - 2011-06-14 23:10:22 - Graham Ellis

It took me about 20 lines of code - just over 300 bytes - to come up with a Perl program which looks in the current directory and everywhere below for all files over a certain size. Have a look at the code [here] (opens in a new window).

Even on such a short piece of code, written in front of delegates on this week's Perl Course, there are a whole lot of design decisions that need to be made, many of which are quite out of the scope of a course, since they reflect the wider working environment of how the program will be used and who'll be maintaining it into the future. Let's look at some of those

On coding:

• Should be code be commented every line, in blocks, or not at all (as it's really very simple for experienced Perl programmers to read something this short)
• Should the code be selfcommenting, with variable names that describe the things they contain, and block nicely inset - or should it be "compact is good" on the basis that flannel is a good thing.
• How about code shortenings, since we can assign and use together and reduce code length that way
• Do we go for efficiency, or readability? -l $current on a file system object followed by -s $current on the same file requires two references back to the file system; we could use stat or -s _ for the second reference.

On functionallity:

• How should we handle files that may occur more than once in the file name tree, via symbolic or hard links (Linux, Unix), or shortcuts (Windows)?
• Do we want to look at hidden and system files too?
• How about a useage line with a -h switch?
• What about subdirectoies that we know to exist but cannot read
• Should we add summary stats?