Exercises, examples and other material relating to training module P301. This topic is presented on public course Perl for Larger Projects
Perl variables come in seven types. You should be familiar with scalars, lists and hashes before you start this module, but you've probably still got more to learn. And how about code variables, file handles and typeglobs?
|Articles and tips on this subject||updated|
|3430||Sigils - the characters on the start of variable names in Perl, Ruby and Fortran|
A sigil (from Latin sigillum "seal") is a symbol created for a specific magical purpose. A sigil is usually made up of a complex combination of several specific symbols or geometric figures, each with a specific meaning or intent. In computer programming, a sigil is a special symbol attached to a variable ...
|3059||Object Orientation in an hour and other Perl Lectures|
I enjoy the occasional course that's different in its design and specification, and yesterday was one of those - more lectures that training, on intermediate and advanced Perl, for a group of eight delegates who were all well experienced at PHP, but Perl "dabblers" to this point. During the day, we ...
|2972||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 ...
|2877||Further more advanced Perl examples|
I've uploaded a further batch of new examples (that makes around 40 in total!) from the private Perl course that I ran from Wednesday through Saturday last week - many of them adding a new twist on to previous examples. If you read a comment below and thing "that's what I'm looking for an example of", ...
|1946||Variable Types in Perl|
In Perl, you have "autovivification" where variables are created when they have a values set in them, without the need to declare them. Some authorities will tell you that they are also "autotyped" in that Perl knows what to store in them automatically too, and to some extent that's true ... but the ...
|2374||Lead characters on Perl variable names|
Perl variable names mostly start with a special character:
$ for a scalar variable - that's a variable that can hold an integer, a float, a string, a reference, or a compiled regular expression (that last not being terribly common).
@ for a list - that's an ordered collection of scalars, indexed from ...
|2241||Perl references - $$var and \$var notations|
In Perl, if I write:
$stuff = "Porridge";
then I'm setting up a variable to contain the value "Porridge".
If I write:
$stuffat = \$stuff;
then I'm setting up a variable to contain the ADDRESS OF the variable $stuff.
So if $stuff was in memory at (hex)fe80 ... then $stuffat will be assigned that value ...
|1581||What is an lvalue? (Perl, C)|
An lvalue is an expression that you can write on the left hand side of an assignment statement - in other words an expression that defines a specific memory address of a variable.
The most common lvalues are simple variables or array / list / hash / dictionary members ... for example
$hello = "Hello ...
|975||Answering ALL the delegate's Perl questions|
During courses, questions arise. "I'll get back to that" could make people feel that I'm brushing something off ... except that I explain, early on, that some questions require a great deal of background knowledge to be answered sensibly. And I keep a list of topics that I'll be getting back to ...
Examples from our training material
|danger|| What variables have I used?|
|dele|| delete, undef, defined and exists|
|fact|| recursion in Perl|
|gawd|| Typeglob - one each of file handle, scalar, hash and list|
|henry|| Variable types|
|iiw|| my, local and global variables|
|mkd2|| Anonymous lists using [ and ]|
|mkpascal|| Pascal's triangle; clever use of formatting|
|my2|| scoping with "my"|
|pers|| persistent my variable|
|phash|| data munging - unpack, splice, regular expressions etc|
|ref2|| Modifying values passed in to a subroutine|
|ref3|| handling a list of lists element by element, by row, and as a whole|
|scal_type|| ref function - what is in a scalar|
|scope|| variable scope illustration|
|sfact|| Beware of variable scope in recursive code|
|sfact1|| Use of strict to flag scoping dangers|
|sfact3|| Using package names to supress strict warnings|
|splitter|| select and typeglobs for file handles - alternative to array of file handles|
|st|| Accessing Perl's symbol tables|
|st2|| Dumping out all variables defined|
|tgd|| typeglobs - a package deal (one of everything!)|
|ty|| Setting up and exercising a typeglob|
|vartypedemo|| 6 variable types in Perl|
|vbn|| Soft References|
Some modules are available for download
as a sample of our material or under an Open Training Notes License
for free download from http://www.training-notes.co.uk
Topics covered in this module
undef and delete.
Further examples using my variables.
Using a reference within a subroutine.
Dynamic creation of structures.
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. Also
available is the Opentalk
Forum for discussion of technical questions.