Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
 
For 2021 - online Python 3 training - see ((here)).

Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7.
We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.

Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc.
Perl - Subs, Chop v Chomp, => v ,

During courses, I end up writing a lot of short demonstrations to show particular features of a language - this week, it's a Perl Programming Course so those examples are in Perl.

Some interesting Perl facts ...

a) The => operator can be used to replace the , ("the equals, greater than can be used to replace the comma")

b) chop and chomp have the same effect on a line of text just read in from STDIN (which usually means "read from the keyboard")

c) It's a good idea to take commonly repeated pieces of code and save them in a block - called a sub or subroutine in Perl - so that you don't have to keep repeating yourself AND so that you can present your user with a consistent interface

The programs I come up with are odd / quirky / memorable and if you look back at them later will leave the new reader scratching his or her head - but the key word is memorable. Here's the program that went some of the way to explaining the key perl facts above:

sub getui {
  print "$_[0] - ";
  chomp ($rv = <STDIN>);
  return $rv;
  }
 
print "How kids yagot? ";
chomp($nk = <STDIN>);
 
print "And how many goldfish? ";
chop($ng = <STDIN>);
 
$nz = getui("how many zebras?");
 
print "Actimel $nk pounds\n";
print "Cream Cheese ",$nk," kiddoes\n";
print "Milk $nk pounds\n";
print "Yoghurt "=>$ng=>" goldfish\n";
print "Bananas ",$nz," zebras\n";


Learning in this way is not only useful, but fun! If you're looking for the dates of the next public Perl course ... as I write (early October 2008) the next course starts on 27th October, and if you're reading this later on the archive and have missed that start date, you can find what's coming up here in our index of courses. I look forward to helping many more people (such as yourself, perhaps?) enjoy learning Perl!




Sample Output:

Dorothy:p1 grahamellis$ perl tootoo
How kids yagot? 3
And how many goldfish? 7
how many zebras? - 4
Actimel 3 pounds
Cream Cheese 3 kiddoes
Milk 3 pounds
Yoghurt 7 goldfish
Bananas 4 zebras
(written 2008-10-08)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
P211 - Perl - Hashes
  [240] Conventional restraints removed - (2005-03-09)
  [386] What is a callback? - (2005-07-22)
  [738] (Perl) Callbacks - what are they? - (2006-05-30)
  [930] -> , >= and => in Perl - (2006-11-18)
  [968] Perl - a list or a hash? - (2006-12-06)
  [1334] Stable sorting - Tcl, Perl and others - (2007-09-06)
  [1705] Environment variables in Perl / use Env - (2008-07-11)
  [1856] A few of my favourite things - (2008-10-26)
  [1917] Out of memory during array extend - Perl - (2008-12-02)
  [2833] Fresh Perl Teaching Examples - part 2 of 3 - (2010-06-27)
  [2836] Perl - the duplicate key problem explained, and solutions offered - (2010-06-28)
  [2915] Looking up a value by key - associative arrays / Hashes / Dictionaries - (2010-08-11)
  [2920] Sorting - naturally, or into a different order - (2010-08-14)
  [3042] Least Common Ancestor - what is it, and a Least Common Ancestor algorithm implemented in Perl - (2010-11-11)
  [3072] Finding elements common to many lists / arrays - (2010-11-26)
  [3106] Buckets - (2010-12-26)
  [3400] $ is atomic and % and @ are molecular - Perl - (2011-08-20)
  [3451] Why would you want to use a Perl hash? - (2011-09-20)
  [3662] Finding all the unique lines in a file, using Python or Perl - (2012-03-20)

P209 - Subroutines in Perl
  [96] Variable Scope - (2004-10-22)
  [308] Call by name v call by value - (2005-05-11)
  [357] Where do Perl modules load from - (2005-06-24)
  [531] Packages in packages in Perl - (2005-12-16)
  [588] Changing @INC - where Perl loads its modules - (2006-02-02)
  [775] Do not duplicate your code - (2006-06-23)
  [969] Perl - $_ and @_ - (2006-12-07)
  [1163] A better alternative to cutting and pasting code - (2007-04-26)
  [1202] Returning multiple values from a function (Perl, PHP, Python) - (2007-05-24)
  [1782] Calling procs in Tcl and how it compares to Perl - (2008-09-02)
  [1784] Global - Tcl, PHP, Python - (2008-09-03)
  [1850] Daisy the Cow and a Pint of Ginger Beer - (2008-10-21)
  [1860] Seven new intermediate Perl examples - (2008-10-30)
  [1921] Romeo and Julie - (2008-12-04)
  [2069] Efficient calls to subs in Perl - avoid duplication, gain speed - (2009-03-07)
  [2550] Do not copy and paste code - there are much better ways - (2009-12-26)
  [2929] Passing a variable number of parameters in to a function / method - (2010-08-20)
  [3066] Separating groups of variables into namespaces - (2010-11-24)
  [3574] Perl functions such as chop change their input parameters - (2012-01-10)
  [3833] Learning to use existing classes in Perl - (2012-08-10)

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)
  [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)
  [3329] Perl from basics - (2011-06-20)
  [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)
  [3917] BODMAS - the order a computer evaluates arithmetic expressions - (2012-11-09)
  [4324] Learning to program - variables and constants - (2014-11-22)


Back to
Question Mark - Colon operator (Perl and PHP)
Previous and next
or
Horse's mouth home
Forward to
What a shock
Some other Articles
Caen Hill and Olivers Castle
Dont bother to write a Perl program
Perl - map to process every member of a list (array)
What a shock
Perl - Subs, Chop v Chomp, => v ,
Question Mark - Colon operator (Perl and PHP)
Which is your best hotel room?
FSB - an update.
Claverton Pump
Autumn
4759 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, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 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., 2021: 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/1826_Per ... mp-v-.html • PAGE BUILT: Sun Oct 11 16:07:41 2020 • BUILD SYSTEM: JelliaJamb