Well House Consultants
You are on the site of
Well House Consultants
Open Source Training Courses
hotel accommodation. You are welcome to browse and use
our resources subject to our copyright statement and to add in links from your pages to ours.
Other subject areas - resources
Well House Manor Resources
Object Orientation and General topics
Linux / LAMP / Tomcat Resources
Well House Consultants Resources
C and C++ Resources
Web and Intranet Resources
Perl module P205
Initial String Handling
Exercises, examples and other material relating to training module P205. This topic is presented on public courses Perl Programming
, Perl bootcamp
, Learning to program in Perl
, Perl Programming
One of Perl's great strengths is its string handling. It can perform operations on a character-by-character basis, or on strings as a whole. It also has a powerful facility known as regular expressions, which allows the knowledgable programmer to write one line of code that would otherwise be pages long!
|Articles and tips on this subject||updated|
|3770||Sample answers to training course exercises - available on our web site|
In order to consolidate knowledge that we've just imparted during each module of our courses, we set exercises for the delegates to try out at the end. And we're around and available while they're doing the exercises to check and assist in re-explaining any vital points that they've missed, and to help ...
|3547||Using Perl to generate multiple reports from a HUGE file, efficiently|
If you want to extract two distinct reports from a large data source, there are a number of ways you could do it. The first two are not brilliant:
1. You could read the entire file into memory, and then traverse it several times in a loop. This is a poor solution if the data becomes huge - the footprint ...
|3548||Dark mornings, dog update, and Python and Lua courses before Christmas|
It's significantly darker each morning as we take Gypsy and Billy out for a morning walk. We're out well before sunrise now, which was at 07:29 on his first morning with us, it is at 08:04 today - just a fortnight later - and will be at 08:16 by 31st December. Only from 1st January does it start getting ...
|3411||Single and double quotes strings in Perl - what is the difference?|
In Perl, there's usually more than one way of doing it ...
If you're writing a string of text into your program, your first possibility is to use single quotes - in which case you're writing a literal string with everything between the single quote chartacters included exactly in the string. And your ...
If you find yourself repeating something within a piece of code .... there's probably an easier way. After all, most programmer are lazy and that applies just as much (if not more) to the authors of the languages. Remember to use functions / methods / subs / procs / defs rather than cut and paste, and ...
|3005||Lots of ways of doing it in Perl - printing out answers|
"There's more than one way to do it". So says the first book in our Perl Library - Perl Programming, also known as "The Camel Book". And that eclectic collection of lots of ways of doing the same thing applies all over Perl; when I'm running Perl Courses, I'm often asked "how do I ..." questions and ...
|2963||Removing the new line with chop or chomp in Perl - what is the difference?|
Where Perl supports functions of similar names, you'll find they do similar things - such as chop v chomp.
chop always removes the last character of a string
chomp removes the last character of a string but only if it is a new line
Both chop and chomp alter the variable that's passed ...
|2832||Are you learning Perl? Some more examples for you!|
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 ...
|2816||Intelligent Matching in Perl|
Is 10 greater than 8?
As a number, yes it is ... but if you're comparing character strings and you would for a book's index, then the character "1" comes before the character "8", so in this context the 10 is earlier than (i.e. less than) 8.
Is 14.0 the same as 14?
As a numeric value, yes it is. ...
|2798||Perl - skip the classics and use regular expressions|
Perl includes a number of "classic" string handling functions - things like index to find one string in another and substr to get a substring. But you very rarely need to use them because the other string handling functions that are provided are so much more powerful!
Here's an example - firstly showing ...
|1849||String matching in Perl with Regular Expressions|
Some languages used adaptive or overridden operator to perform a task depending on the operands - for example in Java, the "+" operator adds numbers, but concatenates strings, and in PHP the == operator compares numbers or strings, depending on the operand types. But in Perl 5, it's often up to the ...
|1860||Seven new intermediate Perl examples|
From the "learning to program in Perl" course I'm running this week, I am pleased to present seven new examples ... written during the course, in front of the delegates, to show them NOT ONLY how the code works, BUT ALSO how a programmer will develop such code.
Lists and Context
* If you use an @abc, ...
|1608||Underlining in Perl and Python - the x and * operator in use|
Perl's x operator - yes, that is the letter x - is used to replicate the string on the left the number of times given to the right. "What use is THAT" I have been asked in the past, by delegates feeling that it's a solution looking for a problem. Well - as an example, it's a great way to output just ...
|1195||Regular Express Primer|
Over the years I've been teaching people about Regular Expressions, I've learnt what does and doesn't work in such tuition. A casual question I saw yesterday got me writing, and I've just posted up a new technical article to the solution centre - see here (it will open in a separate window).
|987||Ruby v Perl - interpollating variables|
When printing in Perl, you can drop a variable into a double quoted string ant it will be interpretter for you:
"--- $number ---"
If you want to perform an operation on the variable, though, it's not as easy - you have to come out of the double quoted string, do the calculation, then start another ...
|970||String duplication - x in Perl, * in Python and Ruby|
In Python and Ruby you can duplicate a string by running the multiply operator (*) on a string object, and in perl you can use the x operator. There have been many times when I've looked at this facility and said to myself "very nice, but isn't that a feature looking for a benefit" - in other words, ...
|324||The backtick operator in Python and Perl|
In Perl, and in shell programs too, the backtick operator causes the enclosed string to be executed as a command and the result (as generated on STDOUT) returned.
In Python, it's different. The backtick operator causes the enclosed expression to be evaluated and returned as a string.
See string handling ...
Examples from our training material
|autumn|| Sample answer - course exercise|
|bticks|| backtick operator - runs an operating system command|
|chx|| Comparison of chop and chomp|
|cs|| Exercise answer - completing a sentence|
|deepmidwinter|| Course exercise - sample answer|
|dqs|| Single, double and back quotes|
|eqt|| Numeric, String and match comparisons|
|fd|| Delimiting a variable name|
|fil_tar|| Filtering a log file for 'lua'|
|finsent|| Trimming a sentence|
|firststring|| low level string functions demonstrated|
|greeting|| use of x operator|
|heredoc|| Use of a here document for copyright block|
|im10|| Intelligent match on scalars|
|izit|| ~~ =~ eq and == operators compared|
|lms|| comparing . and ,|
|midwinter|| Course exercise - sample answer|
|pattern|| Regular expression learning tool|
|perlstring|| Ways of writing strings in Perl|
|pf2|| Filter roads.xyz to match a pattern (using open or die)|
|pfilter|| Filter roads.xyz to match a pattern|
|pig|| Regular expression - first example with anchors, literals, groups, and counts|
|plook|| Simple example of reading and filtering a data file|
|prop2|| Using double quoted strings to change case|
|prop3|| single and double quotes, q and qq strings|
|proper|| Case changes on string|
|pws|| Use of eq rather that == for string comparison|
|romance|| Quoted strings, qq strings and here documents|
|sc|| Case insensitive comparison|
|singlename|| regex to look for a single name|
|stringers|| Strings in Perl|
|winter|| Course exercise - sample answer|
|xz|| Printing out variable contents with labelling text|
PicturesPerl is a great tool for handling huge data files
Some modules are available for download
as a sample of our material or under an Open Training Notes License
for free download from [here]
Topics covered in this module
String handling functions.
String handling operators.
qq and q strings.
Comparing strings exactly.
Comparing strings to regular expressions.
If you are looking for a complete course and not just a information on a single subject, visit our Listing and schedule
Well House Consultants specialise in training courses in
. We run
throughout the UK (and beyond for longer courses), and
at our training centre in Melksham, Wiltshire, England.
It's surprisingly cost effective to come on our public courses -
even if you live in a different
country or continent to us
We have a technical library of over 700 books on the subjects on which we teach.
These books are available for reference at our training centre.