It's refreshing to teach Perl to a class of bright but brand new programmers, which I'm doing in Edinburgh this week. For a class on novices really make me think "why" at some of the aspects us old hacks take for granted. And - yes - I'm delighted to step back to the basics and explain.
Along these lines ... here's a Perl program from today with, incredibly even for me, every line commented - in fact, I wrote the comments first - like an ASCII flowchart if you like, then added the code to perform each action thereafter.
# set up the tax rate
$factor = 1.2;
# Ask for the amount net
print "How much does the storekeeper want for this widgit? ";
# read and store the answer
$net = <STDIN>;
# calculate the gross amount
$gross = $factor * $net;
# and print it out
print "The amount to charge is ",$gross,"\n";
"Did you have to put the 1.2 into a separate variable - couldn't you just have multiplied by it?" (Discussion of the dangers of riffling your code with constants)
"Is the spacing important" (Discussion of the spaces to make the layout look good, and also of those extra spaces in the strings being printed out)
And looking at variable naming, printed result accuracy, whether the report generated should echo the input data, and more ... amazing how much you can learn from 4 lines of executable code!
(written 2011-06-20)
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
Q904 - Object Orientation and General technical topics - Analysing a Programming Task [747] The Fag Packet Design Methodology - (2006-06-06)
[1345] Perl and Shell coding standards / costs of an IT project - (2007-09-11)
[1513] Perl, PHP or Python? No - Perl AND PHP AND Python! - (2008-01-20)
[1607] Learning to program in Perl - (2008-04-11)
[1850] Daisy the Cow and a Pint of Ginger Beer - (2008-10-21)
[1853] Well structured coding in Perl - (2008-10-24)
[2327] Planning! - (2009-08-08)
[2715] Uploading an image, document or pdf via a browser (php) - (2010-04-10)
[2834] Teaching examples in Perl - third and final part - (2010-06-27)
[3366] Specification, Design, Implementation, Testing and Documentation - stages of a (Java) programming project - (2011-07-21)
[3461] From flowchart to program - code design for the newcomer - (2011-09-29)
[3895] Flowchart to program - learning to program with Well House - (2012-10-14)
P202 - Perl Fundamentals [184] MTBF of coffee machines - (2005-01-20)
[748] Getting rid of variables after you have finished with them - (2006-06-06)
[1312] Some one line Perl tips and techniques - (2007-08-21)
[1448] Question on division (Java) - Also Perl, PHP, Python ... - (2007-11-28)
[1726] Hot Courses - Perl - (2008-07-28)
[1826] Perl - Subs, Chop v Chomp, => v , - (2008-10-08)
[1946] Variable Types in Perl - (2008-12-15)
[2442] Variable storage - Perl, Tcl and Python compared - (2009-10-08)
[2832] Are you learning Perl? Some more examples for you! - (2010-06-27)
[2876] Different perl examples - some corners I rarely explore - (2010-07-18)
[3059] Object Orientation in an hour and other Perl Lectures - (2010-11-18)
[3102] AND and OR operators - what is the difference between logical and bitwise varieties? - (2010-12-24)
[3278] Do I need to initialise variables - programming in C, C++, Perl, PHP, Python, Ruby or Java. - (2011-05-05)
[3398] Perl - making best use of the flexibility, but also using good coding standards - (2011-08-19)
[3542] What order are operations performed in, in a Perl expression? - (2011-12-07)
[3574] Perl functions such as chop change their input parameters - (2012-01-10)
[3917] BODMAS - the order a computer evaluates arithmetic expressions - (2012-11-09)
[4324] Learning to program - variables and constants - (2014-11-22)
Some other Articles
Honesty and a friendly welcome goes a long wayDNA to Amino Acid - a sample Perl scriptComparing Alloa and Melksham - stations and servicesA 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 Shelter