Chapter 25 First Perl Program
Scripting languages, like Perl, are very commonly used in bioinformatics. As a generous scripting language, Perl have many advantages: easy to use, free for all operating systems like Linux, designed for working with text files (tab-delimited files). It’s one of the most popular language in bioinformatics. Moreover there are many scripts and modules available. Additionally, there are a lot of resource on Internet.
25.1 First Program
As all other programming books, we begin with a “Hello world” program.
#!/usr/bin/perl
#Printing a line of text “Hello, Bioinformatics”
print "Hello, Bioinformatics!\n";
This program show how to display a line a text in Perl. It have several features. We go through each line in detail.
Line 1 is what we call shebang line. This line starts with shebang construct (#!
). /usr/bin/perl
indicates the path of the Perl interpreter.
Line 3 shows how to print a line of text in Perl. Nearly all programming language use print to display texts on the screen. Here, print is a built-in function in Perl. It print the string of characters (its arguments) between quotation marks (“” or ’’).
perl code_perl/hello_bioinfor.pl
## Hello, Bioinformatics!
However the characters \n
are not displayed. Here backslash \
is a start of an escape sequence. It changes the meaning of the character after it. The backslash \
and n
together (\n
) form an escape sequence and signify a newline. Other examples are \t
(tab) or \$
(= print an actual dollar sign, normally a dollar sign has a special meaning). We’ll see more escape sequences in 7.1.
You can try to remove \n
in the program to see what will happen. This will give you a dee per understanding of the program.