One of the things that you'll get on a Well House Consultants course is new code written by the tutor in front of your very eyes. We do that because:
• you need to learn not only how code works, but also the though code process behind the code - not only how it is written in a ceratyin way but why.
• you need to be able to ask questions as we go along, and not just when presented with a final answer.
• you gain far more from your course if we use your data / tailor the course to your needs as we go along - if we keep it relevant.
There's a downside as far as we're concerned, though - it means that we need to have every single class taught by someone who knows Perl REALLY well - we can't put in a "read the book to the class" guy or gal if we're a bit busy one week. But that downside to us is the most tremendous upside to you - you get someone who REALLY know Perl well, and that's on every course.
Often, the examples aren't especially tidy when we finish the course; they may be emailed to the delegates if requested, or they may be tossed as having fulfilled their purpose. However, I have spent a great deal of this weekend documenting the Perl examples I wrote to a higher standard, so that they're suitable for publication and reuse.
This post is the first of three that will introduce the new examples, subject by subject. Please follow links to the source code where it's of interest, as you'll find further documentation - sometimes line by line where it's appropriate.
And if you would like to learn Perl from us ... please look at our Perl training course options
. Or send me an email to discuss your own particular needs.
P201- Perl Introduction
There's a lot to Perl - and early on in learning the language, delegates need some overview of where they're headed - a morale boosing view to say "look - with a few simple elements, you'll be amazed what you can do".
So at the end of the first day of training, I write some fresh examples using what I've taught in that first day, with a few extras along the "we'll see this in the next day orr two" lines.
Here are those examples from last week ...
Counting records of different types from a large log file - [source]
An extended version of that demonstration, which analyses all the possible record types - [source]
And another example - this time with sorted output [source]
And finally, by special request of two of the delegates, output in XML - [source]
P202 - Perl Fundamentals
Before you start coding in ANY language, you should think ahead and plan what you're doing - and a good way to do this is to write your comments first. I did this during the recent Perl course, with programs to calculate body/mass index.
First sample program - [sources]
I then went on to add conditionals to the code - not only does the second program tell you your BMI, but it tells you what it means (please consult your doctor and don't trust us - it's just a simple general case on the Perl course and we cannot take responsibility, etc ...)
Second sample program - [here]
The final example adds a loop - you enter your height and weight, and it produces a whole table to show what happens to your BMI as you loose and gain weight (there's an assumption that your height won't change!)
Third sample program - [here]
P204 - Conditionals and Loops in Perl
Input, calculations, output. Conditionals and loops. Once you've got those basics, you can write some useful programs.
P205 - Initial String Handling in Perl
Does 3 equal 3.0? You may say "yes" and you may say "no" - both answers are sort of correct - the real question is "what to you mean by equals".
Perl has three different ways of comparing - and all are illustrated in a sample program - [here]
- which I wrote during the course last week.
To add further complexity, but to make Perl much easier to use once you understand it, Perl 5.10, Perl 5.12 and Perl 6 onwards have an extra operator - the intelligent match operator - which chooses between the three well established comparisons, and others beside, if you use ~~. See [here]
for more details.
What's the difference between single and double quotes? What are q and qq? What is a "here document". There's an explantion in the comments - and a sample in the source - [here]
P206 More Perl Loops and Conditionals
Perl has a large number of ways of doing anything - and nowhere will you see that more than with loops and conditionals - a program showing some of the more esoteric examples can be found [here]
- an excersize which I asked delegates to do (then did myself) to make use of a wide range of alternatives.
Some of the extra ways - though are VERY useful in use, such as the ? : operator which is a short form of if and else. I wrote an example, and it's documented [here]
Pictures - delegates on last week's course. And it's not ALL study - on the evenings, I took a stroll in the countryside near to us, as I often do. And I was delighted to be accompanied by several delegates and to help promote our motto - "Come as a student, leave as a friend"
To be continued ....
Three part article ... this is part 1. Jump to part   (written 2010-06-27)
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articlesP206 - Perl - More Loops and Conditionals 
Perl - redo and last without a loop - (2004-12-02) 
What - no switch or case statement? - (2005-05-03) 
The ternary operator in Python - (2006-03-25) 
Breaking a loop - Ruby and other languages - (2006-12-03) 
Smart English Output - via PHP and Perl ? : operator - (2007-05-18) 
for loop - how it works (Perl, PHP, Java, C, etc) - (2007-06-06) 
Ruby, C, Java and more - getting out of loops - (2008-03-19) 
Saying NOT in Perl, PHP, Python, Lua ... - (2008-07-04) 
Question Mark - Colon operator (Perl and PHP) - (2008-10-08) 
For loop - checked once, or evety time? Ruby v Perl comparison and contrast - (2010-04-07) 
switch and case, or given and when in Perl - (2010-06-17) 
Setting a safety net or fallback value in Perl - (2010-06-19) 
A pint of Black Rat, and a lazy barman - (2010-06-25) 
Alternative loops and conditionals in Ruby and Perl - (2010-07-28) 
Multiway branches in Perl - the given and when syntax - (2010-09-22) 
Some more advanced Perl examples from a recent course - (2010-09-27) 
How a for loop works Java, Perl and other languages - (2011-03-12) 
Perl - making best use of the flexibility, but also using good coding standards - (2011-08-19) 
Ruby v Perl - a comparison example - (2012-02-21) 
While, for, foreach or something else to loop. - (2012-11-06)P205 - Perl - Initial String Handling 
Here documents - (2004-08-28) 
x operator in Perl - (2005-03-22) 
The backtick operator in Python and Perl - (2005-05-25) 
String duplication - x in Perl, * in Python and Ruby - (2006-12-07) 
Ruby v Perl - interpollating variables - (2006-12-15) 
Regular Express Primer - (2007-05-20) 
Underlining in Perl and Python - the x and * operator in use - (2008-04-12) 
String matching in Perl with Regular Expressions - (2008-10-20) 
Seven new intermediate Perl examples - (2008-10-30) 
Perl - skip the classics and use regular expressions - (2010-06-08) 
Intelligent Matching in Perl - (2010-06-18) 
Removing the new line with chop or chomp in Perl - what is the difference? - (2010-09-21) 
Lots of ways of doing it in Perl - printing out answers - (2010-10-19) 
Single and double quotes strings in Perl - what is the difference? - (2011-08-30) 
Using Perl to generate multiple reports from a HUGE file, efficiently - (2011-12-09) 
Dark mornings, dog update, and Python and Lua courses before Christmas - (2011-12-10) 
Sample answers to training course exercises - available on our web site - (2012-06-21)P204 - Perl - Conditionals and Loops 
Wimbledon Neck - (2005-06-20) 
-> , >= and => in Perl - (2006-11-18) 
Lexical v Arithemetic testing, Bash and Perl - (2007-12-11) 
Decisions - small ones, or big ones? - (2007-12-18) 
Learning to program in Perl - (2008-04-11) 
Equality and looks like tests - Perl - (2008-07-29) 
Ternary operators alternatives - Perl and Lua lazy operators - (2009-08-12) 
Do not copy and paste code - there are much better ways - (2009-12-26) 
Increment operators for counting - Perl, PHP, C and others - (2010-10-18) 
Does a for loop evaluate its end condition once, or on every iteration? - (2011-08-18) 
Flowchart to program - learning to program with Well House - (2012-10-14) 
Showing what programming errors look like - web site pitfall - (2013-03-06) 
Learning to Program - the conditional statement (if) - (2014-11-21) 
Learning to program - Loop statements such as while - (2014-11-22)P202 - Perl Fundamentals 
MTBF of coffee machines - (2005-01-20) 
Getting rid of variables after you have finished with them - (2006-06-06) 
Some one line Perl tips and techniques - (2007-08-21) 
Question on division (Java) - Also Perl, PHP, Python ... - (2007-11-28) 
Hot Courses - Perl - (2008-07-28) 
Perl - Subs, Chop v Chomp, => v , - (2008-10-08) 
Variable Types in Perl - (2008-12-15) 
Variable storage - Perl, Tcl and Python compared - (2009-10-08) 
Different perl examples - some corners I rarely explore - (2010-07-18) 
Object Orientation in an hour and other Perl Lectures - (2010-11-18) 
AND and OR operators - what is the difference between logical and bitwise varieties? - (2010-12-24) 
Do I need to initialise variables - programming in C, C++, Perl, PHP, Python, Ruby or Java. - (2011-05-05) 
Perl from basics - (2011-06-20) 
What order are operations performed in, in a Perl expression? - (2011-12-07) 
Perl functions such as chop change their input parameters - (2012-01-10) 
BODMAS - the order a computer evaluates arithmetic expressions - (2012-11-09) 
Learning to program - variables and constants - (2014-11-22)P201 - Perl - Introduction 
Release numbers - (2004-08-23) 
Programming languages - a comparison - (2005-05-20) 
Central London Courses - Perl, PHP, Python, Tcl, MySQL - (2005-07-18) 
Learning to program in Perl or PHP - (2006-01-26) 
Twice is a co-incidence and three times is a pattern - (2006-02-07) 
Perl - multiprocess applications - (2006-02-13) 
Choosing the right language - (2006-03-01) 
Testing you Perl / PHP / MySQL / Tcl knowledge - (2006-04-19) 
How to debug a Perl program - (2006-06-04) 
Is Perl being replaced by PHP and Python? - (2006-08-27) 
The LAMP Cookbook - Linux, Apache, MySQL, PHP / Perl - (2006-11-13) 
Q - Should I use Perl or Python? - (2008-07-23) 
Perl v PHP, choosing the right language - (2008-08-14) 
Perl and Blackberries - (2008-10-23) 
Converting to Perl - the sort of programs you will write - (2009-03-08) 
What is Perl? - (2010-06-15)
Some other Articles
Perl - the duplicate key problem explained, and solutions offeredA course is more than just a chap giving a lectureTeaching examples in Perl - third and final partFresh Perl Teaching Examples - part 2 of 3Are you learning Perl? Some more examples for you!Recording (a macro) in viPoulshot Village FeteDauncey Gardens, MelkshamSharing our programs - easy. Sharing our data - harder.Melksham - a gem in Wiltshire