As your code grows in size, you'll want to divide it down into manageable chunks for ease of maintenance, and so that you can reuse logic at different points in the same application, or even from different applications. Perl's way of naming a block of code is a "subroutine".
This topic is presented on public courses
Perl Programming,
Perl bootcamp
Examples from our training material
| bridges.pm | subroutines called up from example applications |
| courses.pl | Sample (test) program to try out a diary |
| cov2.pm | Coverage as a class. Allows multiple parallel coverage sets! |
| coverage.pm | Routines to combine integer ranges to provide overall coverage information |
| covertest | Sample application - coverage test given ranges of integers |
| ct2 | Coverage test - application using coverage objects |
| diaryev.pm | Sample class for courses.pl demo |
| email.pm | email class of objects - a very simple class |
| globvar | demonstration that variables default to global |
| mailfilter.pm | package to encapsulate information - NOT really objects. |
| mailister2 | including package name in package methods |
| maillister | using a module to retain information |
| mc | Email analysis via a package |
| mc2 | using email objects |
| mf2.pm | package of subroutines for mailfilter2 |
| ms2 | calling subroutines in a different file |
| mysub | calling a subroutine in the same file |
| myvar | Use of my to reduce variable persistance and scope |
| subgetnum | Sample use of subroutines - returned parameters |
| subgnrange | Passing parameters in and out of subroutines |
| substamp | Sample use of subroutines |
| valread.pm | standard subroutines to include in several programs |
Background information
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
What are subroutines and why?.
The limitations of "single block code".
First use of subroutines.
Structured programming.
Object oriented programming.
Calling a subroutine.
Passing values out of subroutines.
Passing values in to subroutines.
Writing your own subroutine.
Passing parameters in.
Returning values.
Writing subroutines in a separate file.
Scope.
Global Scope.
my variables.
A test program:.
packages.
Calling objects.
Writing a class - an introduction.
Complete learning
If you are looking for a complete course and not just a information on a single subject, visit our
Listing and schedule page.
Well House Consultants specialise in training courses in
Python,
Perl,
PHP, and
MySQL. We run
Private Courses throughout the UK (and beyond for longer courses), and
Public Courses 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 600 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.