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))
Teaching examples in Perl - third and final part

Three part article ... this is part 3. Jump back to part [1] [2]

Following on from two earlier posts, here is the final third of the new examples that I wrote during last week's Perl course, and to which I have added extra documentation over the last couple of days.

P212 More on Character Strings

"Does this line contain a possible email address" has a simple answer - yes, or no.

But if the answer is "yes", then there are other questions that arise - corollaries - to which you would like an answer. It's the same in real life ...

"What's the effect of drinking a pint of Black Rat?" The obvious answer is that you get a bit tipsy (or very tipsy if you'e a lightweight). But there are other answers too - the landlord is £2.80 (or however much) richer. There's a glass to was up. You need to visit the loo ...

How can you get at these other answers? In Perl, they're saved into special variables such as $& for the bit of the string that matched your pattern, $1, $2 and so on for the parts of that which match your capture parenthesis - if any. And so on.

I wrote a sample program that shows this in Perl - [source].

There's also a use of these special variable highlighted in a post code hunter [here]

The substitute operator lets you match a regular expression (one or more times) in an incoming string, and replace the matched text with another string, or with the result of evaluating an expression. The output string may depend on (take some of its values from) the incoming string, based on capture parenthesis.

It's much easier to see an example - there's commented source code [here].

P213 Creating your own Perl classes and modules

What does object orientation bring you? It brings the ability to separate out the code that's associated with a type of data from the calling application, and the ability to define a whole series of data types based on a parent "class".

In Perl, it's implemented through packages and modules, and during the recent course I wrote two files which I'll share here.

Without classes - a piece of "control" code using a package - [source]
With classes - the same example, but updated to use objects - [source]

P258 Perl - operating system specific. Unix, Solaris, OS X and Linux

Perl is operating system independent - or largely so. If you code along the lines of "run this operating system command", though, it will only work for you on machines that support that command.

I have a fresh example - [source code here] which runs a df -k command on Unix / Linux in a variety of ways ...

P403 The Common Gateway Interface to Perl

In my early days of teaching Perl, many of our customers were using the Common Gateway Interface (CGI) to hook perl scripts up to web URLs. And very good that was too. But these day, PHP, Ruby on Rail, Django, Java's JSPs and Servlets, and Perl's own Mason - amongst others - have come along, and their specific systems that make the web work so much more integrated. Does CGI still have a place, then?

Yes - it has some niches, and one of last week's delegates has one. A whole load of Perl coe, used for data munging and systems admin, and the occasional need to feed some of it back onto the web.

CGI is designed to take a STDIN -> STDOUT Perl program and with a bit of fiddling get it runing on the web, so it should be no surprise to you than our BMI example from last week is available online too ;-)

Source code [here]
And run it [here] ... it's not particularly well laid out on the web - but I have added a couple of security thinsg to ensure that the well know holes are closed.

P667 Handling Huge Data

There are extra considerations you'll want to make when you're handling huge amounts of data - such as efficient ways to handle it in bulk, and ways to "sample" records so that you can run stats based on a manageable subset. We cover many of these techniques on our Perl for Larger Projects course. However, questions came up last week and a short new example, showing elements of what we cover on the later course, was written.

Source code [here] - but please note that is is NOT optimised yet (it's shockingly slow!).

Q904 Analysing a Programming Task

There are some examples that come up during the course that don't logically fit under any particular language element, and here's one of the - so I've indexed it under techniques.

If you want to get several reports from a data flow, you could save that parse tha data multiple times. Yuk! It's better to store the results into a series of variables (use strings that you contatonate, hashes, lists as you feel appropriate) then output each of the complete strings once you've passed through all the data.

Sample source - [here]

For planning a simple application, you need to decide what's to be done once (outside loops) and what needs to be repeated (inside loops). And this requires quite some thought for newcomers to programming.

I wrote an example that used the through process, and over this weekend, after the course, I've added further comments to it. Please take a look [here].

Three part article ... this is part 3. Jump back to part [1] [2]

(written 2010-06-27)

Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
Q904 - Object Orientation and General technical topics - Analysing a Programming Task
  [747] The Fag Packet Design Methodology - (2006-06-06)
  [1345] Perl and Shell coding standards / costs of an IT project - (2007-09-11)
  [1513] Perl, PHP or Python? No - Perl AND PHP AND Python! - (2008-01-20)
  [1607] Learning to program in Perl - (2008-04-11)
  [1850] Daisy the Cow and a Pint of Ginger Beer - (2008-10-21)
  [1853] Well structured coding in Perl - (2008-10-24)
  [2327] Planning! - (2009-08-08)
  [2715] Uploading an image, document or pdf via a browser (php) - (2010-04-10)
  [3329] Perl from basics - (2011-06-20)
  [3366] Specification, Design, Implementation, Testing and Documentation - stages of a (Java) programming project - (2011-07-21)
  [3461] From flowchart to program - code design for the newcomer - (2011-09-29)
  [3895] Flowchart to program - learning to program with Well House - (2012-10-14)

P667 - Perl - Handling Huge Data
  [639] Progress bars and other dynamic reports - (2006-03-09)
  [762] Huge data files - what happened earlier? - (2006-06-15)
  [975] Answering ALL the delegate's Perl questions - (2006-12-09)
  [1397] Perl - progress bar, supressing ^C and coping with huge data flows - (2007-10-20)
  [1920] Progress Bar Techniques - Perl - (2008-12-03)
  [1924] Preventing ^C stopping / killing a program - Perl - (2008-12-05)
  [2376] Long job - progress bar techniques (Perl) - (2009-08-26)
  [2805] How are you getting on? - (2010-06-13)
  [2806] Macho matching - do not do it! - (2010-06-13)
  [3374] Speeding up your Perl code - (2011-07-30)
  [3375] How to interact with a Perl program while it is processing data - (2011-07-31)

P403 - Perl - The Common Gateway Interface
  [45] CGI v mod_perl - (2004-09-11)
  [2238] Handling nasty characters - Perl, PHP, Python, Tcl, Lua - (2009-06-14)
  [2551] Perl and the Common Gateway Interface - out of fashion but still very useful? - (2009-12-26)
  [3445] Perl and CGI - simple form, and monitoring script. - (2011-09-17)

P258 - Perl - Solaris, OSX and Linux
  [1633] Changing a screen saver from a web page (PHP, Perl, OSX) - (2008-05-06)
  [1702] Running operating system commands in Perl - (2008-07-08)
  [2022] Pre and post increment - the ++ operator - (2009-02-03)

P213 - Perl - Creating your own Classes
  [227] Bellringing and Programming and Objects and Perl - (2005-02-25)
  [246] When to bless a Perl variable - (2005-03-15)
  [983] Blessing in Perl / Member variable in Ruby - (2006-12-14)
  [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)
  [1864] Object Oriented Perl - First Steps - (2008-11-01)
  [1925] Introduction to Object Oriented Programming - (2008-12-06)
  [2169] When should I use OO techniques? - (2009-05-11)
  [2877] Further more advanced Perl examples - (2010-07-19)
  [2969] What does blessing a variable in Perl mean? - (2010-09-24)
  [3059] Object Orientation in an hour and other Perl Lectures - (2010-11-18)
  [3098] Learning Object Orientation in Perl through bananas and perhaps Moose - (2010-12-21)
  [3833] Learning to use existing classes in Perl - (2012-08-10)
  [4607] Classes and object - first steps in Perl 6 - (2016-01-02)

P212 - Perl - More on Character Strings
  [453] Commenting Perl regular expressions - (2005-09-30)
  [583] Remember to process blank lines - (2006-01-31)
  [586] Perl Regular Expressions - finding the position and length of the match - (2006-02-02)
  [597] Storing a regular expression in a perl variable - (2006-02-09)
  [608] Don't expose your regular expressions - (2006-02-15)
  [737] Coloured text in a terminal from Perl - (2006-05-29)
  [928] C++ and Perl - why did they do it THAT way? - (2006-11-16)
  [943] Matching within multiline strings, and ignoring case in regular expressions - (2006-11-25)
  [1222] Perl, the substitute operator s - (2007-06-08)
  [1230] Commenting a Perl Regular Expression - (2007-06-12)
  [1251] Substitute operator / modifiers in Perl - (2007-06-28)
  [1305] Regular expressions made easy - building from components - (2007-08-16)
  [1336] Ignore case in Regular Expression - (2007-09-08)
  [1510] Handling Binary data (.gif file example) in Perl - (2008-01-17)
  [1727] Equality and looks like tests - Perl - (2008-07-29)
  [1735] Finding words and work boundaries (MySQL, Perl, PHP) - (2008-08-03)
  [1947] Perl substitute - the e modifier - (2008-12-16)
  [2230] Running a piece of code is like drinking a pint of beer - (2009-06-11)
  [2379] Making variables persistant, pretending a database is a variable and other Perl tricks - (2009-08-27)
  [2657] Want to do a big batch edit? Nothing beats Perl! - (2010-03-01)
  [2801] Binary data handling with unpack in Perl - (2010-06-10)
  [2874] Unpacking a Perl string into a list - (2010-07-16)
  [2993] Arrays v Lists - what is the difference, why use one or the other - (2010-10-10)
  [3100] Looking ahead and behind in Regular Expressions - double matching - (2010-12-23)
  [3322] How much has Perl (and other languages) changed? - (2011-06-10)
  [3332] DNA to Amino Acid - a sample Perl script - (2011-06-24)
  [3411] Single and double quotes strings in Perl - what is the difference? - (2011-08-30)
  [3546] The difference between dot (a.k.a. full stop, period) and comma in Perl - (2011-12-09)
  [3630] Serialsing and unserialising data for storage and transfer in Perl - (2012-02-28)
  [3650] Possessive Regular Expression Matching - Perl, Objective C and some other languages - (2012-03-12)
  [3707] Converting codons via Amino Acids to Proteins in Perl - (2012-04-25)
  [3927] First match or all matches? Perl Regular Expressions - (2012-11-19)
  [4452] Binary data handling - Python and Perl - (2015-03-09)

Back to
Fresh Perl Teaching Examples - part 2 of 3
Previous and next
Horse's mouth home
Forward to
A course is more than just a chap giving a lecture
Some other Articles
Respecting our customers anonimity
Lorry Parking in Melksham
Perl - the duplicate key problem explained, and solutions offered
A course is more than just a chap giving a lecture
Teaching examples in Perl - third and final part
Fresh Perl Teaching Examples - part 2 of 3
Are you learning Perl? Some more examples for you!
Recording (a macro) in vi
Poulshot Village Fete
Dauncey Gardens, Melksham
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/2834_Tea ... -part.html • PAGE BUILT: Sun Oct 11 16:07:41 2020 • BUILD SYSTEM: JelliaJamb