Finding your big files in Perl - design considerations beyond the course environment
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
• 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.
• 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? (written 2011-06-14, updated 2011-06-15)
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articlesP207 - Perl - File Handling 
How many people in a room? - (2004-08-12) 
Relative or absolute milkman - (2004-11-10) 
STDIN, STDOUT, STDERR and DATA - Perl file handles - (2005-03-23) 
printf - a flawed but useful function - (2006-02-22) 
Perl - its up to YOU to check your file opened - (2006-02-23) 
Iterators - expressions tha change each time you call them - (2006-04-27) 
Being sure to be positive in Perl - (2006-09-15) 
Some one line Perl tips and techniques - (2007-08-21) 
Good, steady, simple example - Perl file handling - (2007-10-30) 
Reading a file multiple times - file pointers - (2007-11-23) 
stdout v stderr (Tcl, Perl, Shell) - (2007-12-10) 
There is more that one way - Perl - (2008-07-14) 
Formatting with a leading + / Lua and Perl - (2008-10-15) 
Seven new intermediate Perl examples - (2008-10-30) 
Reactive (dynamic) formatting in Perl - (2008-10-31) 
Transforming data in Perl using lists of lists and hashes of hashes - (2009-06-12) 
But I am reading from a file - no need to prompt (Perl) - (2009-09-14) 
File open and read in Perl - modernisation - (2010-06-19) 
Chancellor George Osborne inspires Perl Program - (2010-06-22) 
Fresh Perl Teaching Examples - part 2 of 3 - (2010-06-27) 
Dark mornings, dog update, and Python and Lua courses before Christmas - (2011-12-10) 
Traversing a directory in Perl - (2012-08-08) 
Spraying data from one incoming to series of outgoing files in Perl - (2012-08-15)
Some other Articles
A lot of exercise this weekPerl from basicsSummer Sundays - days out by train from Swindon on the TransWiltsWhy are chefs miserable?Finding your big files in Perl - design considerations beyond the course environmentThe Olympic Torch, and Melksham HouseRabbit ShelterIs Melksham town centre dying?How much has Perl (and other languages) changed?Travelling around