For the last few days, I've been teaching
Learning to Program in Perl. Unlike a conventional course style, for this one I had been asked to assume no prior programming knowledge, and covered first principles such as variables, conditionals, and loops.
Here is one of the examples I wrote during the course ...
# The bit you do at the start
print "Please enter first number ";
$entry = <STDIN>;
$sofar = 0;
$howmany = 0;
# The bit you keep repeating
while ($entry > 0) {
$sofar += $entry;
$howmany++;
print "Please enter next number (0 to end) ";
$entry = ;
}
# The bit you do at the end
print "The total was $sofar in $howmany entries\n";
You'll note how I have divided a straightforward little application into "the bit that's done once, first", "the bit that's repeated", and "the bit that's done at the end. And you'll note too how important the comments are!
Given a couple of days, we moved on from examples like the one above to a program that was reading and analysing a log file ... and coming out with results. Perl is, after all, the Practical Extraction and Reporting Language
(written 2008-04-11, updated 2008-04-12)
Associated topics are indexed under
P204 - Perl - Conditionals and Loops [3397] Does a for loop evaluate its end condition once, or on every iteration? - (2011-08-18)
[3004] Increment operators for counting - Perl, PHP, C and others - (2010-10-18)
[2832] Are you learning Perl? Some more examples for you! - (2010-06-27)
[2711] For loop - checked once, or evety time? Ruby v Perl comparison and contrast - (2010-04-07)
[2550] Do not copy and paste code - there are much better ways - (2009-12-26)
[2351] Ternary operators alternatives - Perl and Lua lazy operators - (2009-08-12)
[1727] Equality and looks like tests - Perl - (2008-07-29)
[1696] Saying NOT in Perl, PHP, Python, Lua ... - (2008-07-04)
[1477] Decisions - small ones, or big ones? - (2007-12-18)
[1468] Lexical v Arithemetic testing, Bash and Perl - (2007-12-11)
[1191] Smart English Output - via PHP and Perl ? : operator - (2007-05-18)
[930] -> , >= and => in Perl - (2006-11-18)
[353] Wimbledon Neck - (2005-06-20)
Q904 - Object Orientation and General technical topics - Analysing a Programming Task [3461] From flowchart to program - code design for the newcomer - (2011-09-29)
[3366] Specification, Design, Implementation, Testing and Documentation - stages of a (Java) programming project - (2011-07-21)
[3329] Perl from basics - (2011-06-20)
[2834] Teaching examples in Perl - third and final part - (2010-06-27)
[2715] Uploading an image, document or pdf via a browser (php) - (2010-04-10)
[2327] Planning! - (2009-08-08)
[1853] Well structured coding in Perl - (2008-10-24)
[1850] Daisy the Cow and a Pint of Ginger Beer - (2008-10-21)
[1513] Perl, PHP or Python? No - Perl AND PHP AND Python! - (2008-01-20)
[1345] Perl and Shell coding standards / costs of an IT project - (2007-09-11)
[747] The Fag Packet Design Methodology - (2006-06-06)
Some other Articles
Gauging point at entrance to Bristols Floating HarbourPHP course dot co, dot ukChew Valley LakesUnderlining in Perl and Python - the x and * operator in useLearning to program in PerlSheep Shearers, Marathon Runners and Ocean SailorsLearning and understanding scripting programming techniquesM25 / South Mimms Service AreaDo not SHOUT and do not whisperAutomating processes through Expect