Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Some more advanced Perl examples from a recent course

I ran an extra Perl for larger projects course, single company, at the tail end of last week and into the weekend (the only gap in my diary for a few weeks!) and - as is often the case on single-company courses - I wrote some new illustrative code to show specific subjects that came up in a different way to they would on a more regular, choreographed course. Actuall I wrote so many that I'm only going to provide links to a handful - but I have added many more to our resources - you'll come across them from time to time if you're looking through our course modules and they'll all be listed in our very long global example, article and blog index.

To mention ...

• Perl doesn't start at the top of the code. You may learn as you delve deeped that it starts at a BEGIN block, and indeed it sorta-does. As you delve still deeper, you'll find that used code runs first, with it's begin block ... and you'll also find things like import, CHECK, INIT and even multiple BEGINs. Then at the end you'll find your END blocks and a whole series of DESTROYs if you have created objects ...

See [here] for an example with BEGIN, INIT and CHECK in use in the same code. And see [here] for an application that uses many of these extra, calling a module [here] with a class code. This latter example takes a horse and rider example; there's much more to having a horse than just buying it and taking it to shows ... a story this example tells!

• The switches to tr and y are rarely mentioned, but very useful. If you're not familiar with tr and y, they do a character by character translation ... which can be modified via a switch (a.k.a. modifier):
c - compliment - i.e. only change characters that do NOT match
s - squeeze - reduce multiple successive output characters to a single character (typically remove padding spaces)
d - delete the characters matched rather than replacing them
There's a new example [here], and a fresh example showing modifiers in matching [here].

• Variable scope is a huge subject - but not one that's naturally covered in peoples first delve into Perl; after all, if you're writing short bits of demo code, it's fine for the variables to be shared all around - the default - while you learn. But once you start needing to structure / segment your code so that it's not all in the same big tank, sloshing around, scope becomes important. By default, variables are global and in a package (i.e. namespace) called main, but you can assign them individually to different namespaces, or set a default namespace via a package. There's a "fundamentals" demonstration of the mechanism [here].

As global variables (the default) can be dangerous, use strict; may be specified to cause Perl to fail with an error if you use variable names that aren't explicity placed in a package, or declared with my, or local or our - the latter making them global, but saying to Perl "I know what I am doing here!". There's an example showing these different scopes, and how they vary, [here].

• Extending variable scope and polymorphism lead us on to Perl's OO capabiities - there are a whole load of examples from the notes and previous courses available in the creating your own classes and more objects module resources.

One new example from last week on the OO side is [this one], which shows a very wide range of features - base classes, inheritance, polymorphism, etc ... and also shows the use of SUPER to call a method from a base class (of course, as Perl allows multiple inheritance you'll be asking me "which base class" ... and the answer has to be that it calls the next method of that name on the search tree, ignoring the one in the current class).

• Over the years we've taught Perl, extras have been added to the language and although the huge change comes at Perl six, some things like given and ~~ are now with us in recent verstions of Perl 5. There was a when - given example just a couple of posts ago, and I have added a sample showing the intelligent match operator [here]. I suspect that in time most matches will be done with ~~ ... but not yet, as so much code needs to run with legacy versions of Perl which don't support it.

That's been a miscellany of examples from Friday and Saturday ... if you're interested in attending our public Perl courses, have a look [here] for details. If you've a group of delagates all wanting the same course at the same time, please ask - we can run private courses at our place, or at yours - and to an agenda that meets your needs.
(written 2010-09-27)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
P301 - Variables in Perl
  [975] Answering ALL the delegate's Perl questions - (2006-12-09)
  [1581] What is an lvalue? (Perl, C) - (2008-03-18)
  [1946] Variable Types in Perl - (2008-12-15)
  [2241] Perl references - $$var and \$var notations - (2009-06-15)
  [2374] Lead characters on Perl variable names - (2009-08-24)
  [2877] Further more advanced Perl examples - (2010-07-19)
  [3059] Object Orientation in an hour and other Perl Lectures - (2010-11-18)
  [3430] Sigils - the characters on the start of variable names in Perl, Ruby and Fortran - (2011-09-10)
  [4398] Accessing variables across subroutine boundaries - Perl, Python, Java and Tcl - (2015-01-18)
  [4608] Introspecion in Perl 6 - (2016-01-02)

P218 - Perl - More Objects
  [227] Bellringing and Programming and Objects and Perl - (2005-02-25)
  [246] When to bless a Perl variable - (2005-03-15)
  [531] Packages in packages in Perl - (2005-12-16)
  [588] Changing @INC - where Perl loads its modules - (2006-02-02)
  [592] NOT Gone phishing - (2006-02-05)
  [656] Think about your design even if you don't use full UML - (2006-03-24)
  [831] Comparison of Object Oriented Philosophy - Python, Java, C++, Perl - (2006-08-13)
  [930] -> , >= and => in Perl - (2006-11-18)
  [1217] What are factory and singleton classes? - (2007-06-04)
  [1320] Perl for Larger Projects - Object Oriented Perl - (2007-08-25)
  [1435] Object Oriented Programming in Perl - Course - (2007-11-18)
  [1664] Example of OO in Perl - (2008-06-03)
  [1665] Factory method example - Perl - (2008-06-04)
  [1819] Calling base class constructors - (2008-10-03)
  [1949] Nuclear Physics comes to our web site - (2008-12-17)
  [2427] Operator overloading - redefining addition and other Perl tricks - (2009-09-27)
  [2651] Calculation within objects - early, last minute, or cached? - (2010-02-26)
  [2717] The Multiple Inheritance Conundrum, interfaces and mixins - (2010-04-11)
  [2811] Igloos melt in the summer, but houses do not - (2010-06-15)
  [2876] Different perl examples - some corners I rarely explore - (2010-07-18)
  [3097] Making Perl class definitions more conventional and shorter - (2010-12-20)
  [3098] Learning Object Orientation in Perl through bananas and perhaps Moose - (2010-12-21)
  [3377] What do I mean when I add things in Perl? - (2011-08-02)
  [3581] Perl - calls to methods that use => - what do they mean? - (2012-01-16)
  [3941] Building an object based on another object in Perl - (2012-12-03)
  [4096] Perl design patterns example - (2013-05-20)
  [4098] Using object orientation for non-physical objects - (2013-05-22)
  [4356] Object factories in C++, Python, PHP and Perl - (2014-12-19)
  [4366] Changing what operators do on objects - a comparison across different programming languages - (2014-12-26)

P210 - Perl - Topicalization and Special Variables
  [493] Running a Perl script within a PHP page - (2005-11-12)
  [639] Progress bars and other dynamic reports - (2006-03-09)
  [969] Perl - $_ and @_ - (2006-12-07)
  [1136] Buffering output - why it is done and issues raised in Tcl, Perl, Python and PHP - (2007-04-06)
  [1221] Bathtubs and pecking birds - (2007-06-07)
  [1232] Bathtub example - (2007-06-14)
  [1289] Pure Perl - (2007-08-03)
  [1444] Using English can slow you right down! - (2007-11-25)
  [1508] How not to write Perl? - (2008-01-15)
  [1704] Finding operating system settings in Perl - (2008-07-10)
  [1705] Environment variables in Perl / use Env - (2008-07-11)
  [1728] A short Perl example - (2008-07-30)
  [1829] Dont bother to write a Perl program - (2008-10-10)
  [1860] Seven new intermediate Perl examples - (2008-10-30)
  [1922] Flurinci knows Raby Lae PHP and Jeve - (2008-12-04)
  [2833] Fresh Perl Teaching Examples - part 2 of 3 - (2010-06-27)
  [3449] Apache Internal Dummy Connection - what is it and what should I do with it? - (2011-09-19)
  [4301] Perl - still a very effective language indeed for extracting and reporting - (2014-09-20)
  [4395] Preparing data through a little bit of Perl - (2015-01-15)
  [4682] One line scripts - Awk, Perl and Ruby - (2016-05-20)
  [4700] Obfurscated code - it might work, but is it maintainable? - (2016-07-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)
  [2815] switch and case, or given and when in Perl - (2010-06-17)
  [2817] Setting a safety net or fallback value in Perl - (2010-06-19)
  [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)
  [2967] Multiway branches in Perl - the given and when syntax - (2010-09-22)
  [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)


Back to
Should the public sector compete with businesses? and other deep questions
Previous and next
or
Horse's mouth home
Forward to
Learning to program - where to start if you have never programmed before
Some other Articles
Creating, extending, traversing and combining Ruby arrays
Why do I need brackets in Ruby ... or Perl, Python, C or Java
Formatting your output - options available in Ruby
Learning to program - where to start if you have never programmed before
Some more advanced Perl examples from a recent course
Should the public sector compete with businesses? and other deep questions
Perl - doing several things at the same time
What does blessing a variable in Perl mean?
Well House Consultants - a potted history
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., 2024: 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/2972_Som ... ourse.html • PAGE BUILT: Sun Oct 11 16:07:41 2020 • BUILD SYSTEM: JelliaJamb