01 Part 1 Getting Started

Contents

  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 is a single line comment.


     #So is this

[code goes here]#And so is this.


= comment

This is
a
multi-line comment

= cut

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:

#!/usr/bin/perl

or
#!/usr/bin/local/perl


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 line 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 Perldoc

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 use the .pl extension

e.g.

<programname.pl;>

#!/usr/bin/perl
print "Hello, world!\n";

To run your program type

perl programname

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


4. Where to find out more...

Websites
CPAN
Learn Perl
Perl.com
Perldoc.com
Perl Mongers
Perl Monks
Perl Paraphernalia
Perl Review
Perl Training
Use Perl

Useful Books

Learning Perl (3rd ed)
Randal L. Schwartz & Tom Phoenix
O'Reilly
ISBN 0-596-00132-0

Perl in a Nutshell (2nd ed)
Ellen Siever, Stephen Spainhour & Nathan Patwardhan
O'Reilly
ISBN 0-596-00241-6

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.

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). Alice Wood

Project Gutenberg newsletter editor