[Courses] Perl course part 1

Alice Wood alice at schiffwood.demon.co.uk
Sat Mar 1 12:26:26 EST 2003

LinuxChix Perl Course Part 1: Getting Started


1) Shebang/Hashbang line
2) Documentation and help
3) Exercises
4) Where to find out more...


1) Shebang/Hashbang line

# (aka "octothorp", or "sharp" or "pound sign" or "hash")
normally begins a comment.  The comment is from the #
to the end of the line.

#i.e. This would be a single-line comment.
   #So is this
<code goes here>#And so is this.

= comment

This is
multi-line comment


There is one exception to this comment assignment and that is
when the comment is followed immediately by a ! ( aka
"exclamation mark", or "bang").  The combination #! is known as
the "she-bang" (a contraction of sharp-bang)or "hash-bang" and it
is the top line of the script in both Perl and shell scripts.
It tells the interpreter where to find the program that should
be used for interpreting this script.

To find out what your she-bang line should read, you need to go to
the command line and type "whence perl" (korn shell), "type
perl" or "which perl" (bash).

Typing "type perl" into my command line gives me

perl is /usr/bin/perl

Then create your she-bang line accordingly:


This means that I need to use #!/usr/bin/perl as my top line.

Notice that, unlike other lines of Perl code, this one does NOT
end in a semi-colon.


2) Documentation and help

There are various methods of getting help with Perl, two of them are
supplied with Perl on your machine. The first is the series of 'man' pages. 
Typing "man perl" on the command line or in a terminal with give you a 302 
introduction page with help on how to get to various types of information
The second is the 'perldoc' series which can be accessed by typing 
"perldoc perldoc". Perldoc is aimed at helping with functions and modules.
To start the 'man' series is probably more useful, and can be helpful reading.
However, this is not for the faint-hearted as they are extremely long.

Updated versions and other documentation can be found at

Note: Some Linux installations come with tkman, this is a browser style
version of the man pages.


3) Exercises

1) Try "type perl" in your command line to establish what your top line
of code should be.

2) Use your answer to the above to try the traditional Hello World program.
Type the following in using any text editor. When you come to save the program 
you will need to save it with .pl as the extension.



print "Hello, world!\n";

To run your program type

perl <programname.pl>

3) Use the man pages to find out what Perl stands for.


4) Where to find out more...

An archive of lessons is being created at


Here there are links to useful websites and other books.

Part 2 of the course will follow on 15th March 2003

Note: The author uses Perl version 5.6.1. All exercises should therefore 
work on later versions. If you wish to find out which version of Perl you are
running type "perl -v" into your command line.

If you have any comments regarding this perl lesson, suggestions for future 
topics, useful website addresses, useful reference material or you just want 
to say what you thought, please send your email to 

alice at schiffwood.demon.co.uk

I will be pleased to hear from you.

Credits and acknowledgements

Thanks to Meryll Larkin and Jacinta Richardson for their help with putting
together this material. 
Sources of material include Learning Perl, Randal Schwartx & Tom Phoenix,
& Perl Training Australia (http://www.perltraining.com.au)

More information about the Courses mailing list