There's a lot of well established Perl code running in many places, using versions of the language that have been used for years. But the language should not stand still, and so extra features get added in at each intermediate release level ... and that then gives us the conundrum of what
we should provide as the major focus of our course, and what
you should use in code you write.
I'll answer the easy question - "what should YOU use" - first. But I'll answer it with another question - "What versions of Perl will your program be required to run on?". If you can answer, with certainty, that you'll be developing and running on Perl 5.10 - then feel free to use the new features if they provide a significant improvement for you in maintainability / readability, or if they allow you to bring in a module that a third party has written and which requires 5.10. But if there's
any chance of Perl being loaded at a pre-5.10 level on
even one system that your code will be running on, then you should avoid the new facilities until such time as the older systems are replaced or upgraded.

The more difficult question is "what should we teach?". On one hand, we want to be truly up to date, and on the other hand we must teach people coding techniques that will allow them to maintain the existing code they have (so must major on the better established features) and will work for them in the new code they have to write. Reports such as
the Perl survey give us an annual update on what levels of Perl people are using, and at present our public courses contain some examples showing the Perl 5.10 features, but do not subsequently rely on them in following examples, preferring to stick with longer-established features of the language. Delegates who will be using Perl 5.10 (or 5.12!) are welcome to use the new features during practical sessions; delegates who will be writing Perl 5.8 compliant code can, though, do all of the practical sessions without resorting to features that won't be available to them when back at work.
What's the big deal anyway?
As an example, perl has lacked a
switch statement since it was written. There have been ways of "kludging" it, but in reality the traditional
switch of other languages - with its need to have a
break at the end of each
case, and often with limitations of what can go in a
case - was pretty nasty. Perl 5.10 (in preparation for Perl 6 syntax) has a
given and
when structure which is a much more modern and nicer (IMHO) implementation of a multiway branch. There's an example
[here] on our site.
You'll note that
switch and
case from other languages are replaced by
given and
when (to signify different use) in the headline examples. [[You'll also find that good ole eclectic Perl does actually now allow for the "switch" and "case words to be used too :-( ... see
[here].]]
When you specify an expression or variable in your
given, that value is stored into $_ for the duration of the switch block (the old value is restored afterwards) so that you can give a whole series of
when clauses which use the new
intelligent match operator (
~~) to test for truth. It sounds very much like a switch so far ... but here comes the big change. Once a case has been matched and acted upon, your program will continue to run from
the end of the switch block. It does not drop through into the next block, as happens in languages where
case is essentially a label. Or - put another way -
given and when implement a multiway branch that does away with the need for a break statement to terminate almost every block. You ARE able to explicitly call up a "drop through and try the next tests too" behavior using a
continue statement.
Example code snippet:
given ($name) {
when (/Ellis/i) { print "An Ellis ... "; continue; }
when ("Graham") { say "exactly Graham"; }
when (/Graham/) { say "contains Graham"; }
when (/Graham/i) { say "contains Graham but case is wrong"; }
default {say "no Graham";}
}
Illustration - Delegates on a recent private Perl course
(written 2010-06-17, updated 2010-06-20)
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
P256 - Perl 6 Look Ahead [89] When will Perl 6 be available - (2004-10-15)
[113] A Parallel for Perl 6 - (2004-11-09)
[550] 2006 - Making business a pleasure - (2006-01-01)
[582] DWIM and AWWO - (2006-01-30)
[995] Ruby's case - no break - (2006-12-17)
[1215] An update on Perl - where is it going? - (2007-06-03)
[1417] What software version do we teach? - (2007-10-31)
[1721] Perl 6 - When will we have a production release? - (2008-07-26)
[2559] Moving the product forward - ours, and MySQL, Perl, PHP and Python too - (2010-01-01)
[2816] Intelligent Matching in Perl - (2010-06-18)
[2817] Setting a safety net or fallback value in Perl - (2010-06-19)
[2967] Multiway branches in Perl - the given and when syntax - (2010-09-22)
[3077] Perl 6 - significantly nearer, and Rakudo looks very good - (2010-12-02)
P206 - Perl - More Loops and Conditionals [138] Perl - redo and last without a loop - (2004-12-02)
[299] What - no switch or case statement? - (2005-05-03)
[657] The ternary operator in Python - (2006-03-25)
[962] Breaking a loop - Ruby and other languages - (2006-12-03)
[1191] Smart English Output - via PHP and Perl ? : operator - (2007-05-18)
[1220] for loop - how it works (Perl, PHP, Java, C, etc) - (2007-06-06)
[1582] Ruby, C, Java and more - getting out of loops - (2008-03-19)
[1696] Saying NOT in Perl, PHP, Python, Lua ... - (2008-07-04)
[1825] Question Mark - Colon operator (Perl and PHP) - (2008-10-08)
[2711] For loop - checked once, or evety time? Ruby v Perl comparison and contrast - (2010-04-07)
[2824] A pint of Black Rat, and a lazy barman - (2010-06-25)
[2832] Are you learning Perl? Some more examples for you! - (2010-06-27)
[2892] Alternative loops and conditionals in Ruby and Perl - (2010-07-28)
[2972] Some more advanced Perl examples from a recent course - (2010-09-27)
[3200] How a for loop works Java, Perl and other languages - (2011-03-12)
[3398] Perl - making best use of the flexibility, but also using good coding standards - (2011-08-19)
[3619] Ruby v Perl - a comparison example - (2012-02-21)
[3914] While, for, foreach or something else to loop. - (2012-11-06)
Some other Articles
Some more pictures ...File open and read in Perl - modernisationswitch and case, or given and when in PerlPython - splitting and joining stringsIterating over a Perl list and changing all itemsWhat is Perl?Igloos melt in the summer, but houses do notA course review - for the tutor to complete