Home Accessibility Courses Diary The Mouth Facebook Resources Site Map About Us Contact
Perl from basics

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
P202 - Perl Fundamentals
  [3917] BODMAS - the order a computer evaluates arithmetic expressions - (2012-11-09)
  [3574] Perl functions such as chop change their input parameters - (2012-01-10)
  [3542] What order are operations performed in, in a Perl expression? - (2011-12-07)
  [3398] Perl - making best use of the flexibility, but also using good coding standards - (2011-08-19)
  [3278] Do I need to initialise variables - programming in C, C++, Perl, PHP, Python, Ruby or Java. - (2011-05-05)
  [3102] AND and OR operators - what is the difference between logical and bitwise varieties? - (2010-12-24)
  [3059] Object Orientation in an hour and other Perl Lectures - (2010-11-18)
  [2876] Different perl examples - some corners I rarely explore - (2010-07-18)
  [2832] Are you learning Perl? Some more examples for you! - (2010-06-27)
  [2442] Variable storage - Perl, Tcl and Python compared - (2009-10-08)
  [1946] Variable Types in Perl - (2008-12-15)
  [1826] Perl - Subs, Chop v Chomp, => v , - (2008-10-08)
  [1726] Hot Courses - Perl - (2008-07-28)
  [1448] Question on division (Java) - Also Perl, PHP, Python ... - (2007-11-28)
  [1312] Some one line Perl tips and techniques - (2007-08-21)
  [748] Getting rid of variables after you have finished with them - (2006-06-06)
  [184] MTBF of coffee machines - (2005-01-20)

Q904 - Object Orientation and General technical topics - Analysing a Programming Task
  [3895] Flowchart to program - learning to program with Well House - (2012-10-14)
  [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)
  [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)
  [1607] Learning to program in Perl - (2008-04-11)
  [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)


Back to
Summer Sundays - days out by train from Swindon on the TransWilts
Previous and next
or
Horse's mouth home
Forward to
A lot of exercise this week
Some other Articles
Honesty and a friendly welcome goes a long way
DNA to Amino Acid - a sample Perl script
Comparing Alloa and Melksham - stations and services
A lot of exercise this week
Perl from basics
Summer Sundays - days out by train from Swindon on the TransWilts
Why are chefs miserable?
Finding your big files in Perl - design considerations beyond the course environment
The Olympic Torch, and Melksham House
Rabbit Shelter
4279 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2014: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/3329_Per ... asics.html • PAGE BUILT: Sun Mar 30 15:20:58 2014 • BUILD SYSTEM: WomanWithCat