Tag Archives: lesson1

Perl variables

In any programming language we need to store information, an to retrieve it when needed. Perl has three types of variables:

  • scalar – they can store numbers or text (strings).
  • array – they are ordered lists of scalar.
  • hashes – they are unordered lists of values with a “label” called name.

Scalar are identified by the ‘$’ character. You can assign a value to a scalar with the ‘=’:

$age = 15;
$name = 'Larry';
$age = $age+1;        # an more compact alternative is $age++, if you have to add 1
$combine1 = "$name is $age";
$combine2 = '$name is $age';
print "Double quotes:  $combine1\n";
print "Sinngle quotes: $combine2\n;"

This small script has two assignation, a number and a string. Then we increment the $age variable by 1.
Note that for numbers we don’t use any quote, while for string we use single quotes or double quotes. The difference – as mentioned – is that double quotes are interpreted and substitute $name with the content of the variable itself.

Arrays are list of strings. To create a new array the syntax is a list of comma separated scalars enclosed by round brackets:

@array = ('first', 'second', 15, 16);

each element of the array has an index starting from 0, thus the last element of the array in the example has index 3. As each element of the array is a scalar, we refer to it with the “$” sign, specifying the index:

$firstElement = $array[0];

A special variable is created by Perl and contains the index of the last element:

$lastindex = $#array;


$lastElement = $array[$#array];

Finally hashes are unordered lists of couples of scalar: one is the key and has an associated value.  We’ll see hashes in detail in lesson2.

(in Italian) c’è un buon tutorial su array ed hash in questo sito, valido anche per altri argomenti ovviamente… vi consiglio il corso completo come lettura serale ;).

Tagged , , , ,

Perl: Hello World!

Here you are the code of our very first script we made in lesson1:

$yourname = 'George';
print "Hello world!\n";
print "and hello $yourname too!\n";

Remember that if you want to add comments they should be preceded by the # character. The very first line is an instruction for the shell rather than for Perl, but at the moment just remember to add it.

Each instruction has to end with a “;”.

\n is the special way to add a new-line.

Do you remember the difference between double quotes and single quotes?


Tagged ,

HTML: Hello World!

HTML is the very simple language to format web pages. We used HTML as a first use of “simple text” files and our text editor.

Here i report a simple example very similar to the one covered during the first lesson.

<h1>Hello World!</h1>
<p>My first paragraph. Another <strong>great</strong> paragraph!</p>


If you want to test some HTML code without having to create a new text file you can try this website.

Tagged ,

First class lesson: project overview and first Perl script!

Lesson date: March 8th, 2012

We discussed the project goal: a program to design primers for genome finishing.

We introduced the three main tools of the bioinformaticisists: scripting languages, relational databases and HTML for web interfaces.

You were suggested to download and install a programming editor, with syntax highlighting and other advanced features usually lacking on simpler editors and to install Perl if you use Windows.

 Download slides


Installing and testing Perl

Installing Perl

If you have Linux or Mac OS X you have Perl installed by default. For Windows users there are different package to choose from, but a long used and tested is ActiveState Perl. Choose the X_86 version for Windows.
Download and execute the package following the instructions. You can watch this YouTube video to have and idea: the installation process is quite straightforward.

Installing a text editor

  • Under Linux you can use Gedit (in Ubuntu is under Application -> Accessories -> Text Editor). Kate is good as well.
  • Under Mac OS X you can download Text Wrangler, that is available for free at the App Store.
  • Under Windows you can use Crimson Editor.

Testing Perl

Open a shell terminal. (Under Windows hit Start, then choose “Run…” and type cmd in the text input, then hit Enter).

Type the “perl -v” command, without quotes, and hit enter. Is it working?

Tagged ,