Main Content

Perl - making best use of the flexibility, but also using good coding standards

Archive - Originally posted on "The Horse's Mouth" - 2011-08-19 06:56:51 - Graham Ellis

Sometimes, examples written during a course are throw-aways ... but at other times they become a useful addition to our resources. On a private private Perl course that I was running yesterday, and continues today and Monday, I found myself writing a useful piece that shows examples of lots of ways of doing virtually the same thing in Perl - and remember the Perl manta - "There's more than one way of doing it" is the headline at the top of "Perl Programming" - the book that's also known as "the camel book" and "The Perl bible".

What does the new example (which you can show [here] in a separate frame) cover?

1. 2 different ways of removing the new line from the end of input
2. 6 different ways of formatting a string for output
3. 12 different ways of writing a condtional (optional) statement
4. 8 different ways of writing code that repeats in a loop

In some ways, variety is good. In other ways ... there are just too many ways of doing things; if code is written by someone who "delights" in using many of them, the people who maintain the code may be given a somewhat tougher task. So I'm a strong advocate of teaching delegates to be aware of the options for when they come to maintain code, but to be selective in what they use when it comes to writing new code.

Within different environments and organisations, stanadards (be they formal or infoaml) should be set for Perl coding to ensure that it can be maintained. But there are some things that date back to the early days of Perl such as goto and redo for loops which should really not be written into new code within any standard.

Next public Perl course ... starts 19th September. There's another one from 5th December, and dates for next year will be on the website by the end of this month. There's also an advanced Perl course in November ...