Workshop in Computational Bioskills - Spring 2011
Lesson 2 - Perl I
Introduction to Perl Part 1 - Scalars ($) Part 2 - Lists/Arrays (@) Part 3 - Hash tables/Associative Arrays (%)
Introduction to Perl
Perl: Practical Extraction & Report Language, by Larry Wall (1987)
Why Perl:
What to program in Perl:
- parsing & text manipulations - small programs & scripts
And what not to:
CPU or time-consuming programs (unless you know what you're doing.)
Basic scripting rules:
First line of script must
begin with a shebang (#!),
and then contain the path to the program that interprets your
script (in our case, /usr/bin/perl):
#!/path/to/script/interpreter
On unix platforms, remember
to make the file executable by changing its permissions.
chmod +x
<script-name>
Add comments to your program
by using the hash sign (#).
This declares the rest of the line as a comment.
There's no way of multiline comments (e.g. C's /* comment */).
First program - "hello, world"
#!/usr/bin/perl -w print "hello, world\n"; # that's all, folks.
Variables: Different types:
In the following section
we'll learn more about the different variables types in Perl:
o Scalar ($) - A one-dimensional variable.
o List/Array (@) - Ordered scalar data. (two
dimensional and higher).
o Hash (%) - An associative array.