Perl comes preinstalled on Macs and Linux distributions. It can be downloaded for PCs. Perl is widely used by biologists to solve problems we encounter when handling DNA and protein sequences, file format conversions, as well as many any other tasks that are computationally repetitive. Perl is not the only language for these tasks but one of many. Though, perl is my favorite!
Lesson 1: The skeleton of the perl script & Running a perl script from the command line
The skeleton of the Perl script.
- path to perl
- This can differ on different systems, or if you have a local or nonstandard installation of perl.
- allow for extensive reporting of warnings
- use the strict module
- using the strict library will help you to keep track of variable names and scope
- add comments
- a '#' pound or number sign indicates that the text that follows is a comment
- comments are good to document logic, script names, and script purposes
- the body of you script that does something.
print "Hello! I wrote my first perl script!!\n";
- each line of your script will end with a ';' semicolon.
- print is a function.
- '\n' is the newline character
- Not used in this lesson but it is nice to know that '\t' is the tab character
Running a perl script from the command line.
- Make the script executable. (Note: I will use '%%' to indicate that we are on the command line. Do not type the '%%'.)
%% chmod +x yourScript.pl
- running it from the commmand line
Putting it all together
The complete script:
1 2 3 4
#!/usr/bin/perl -w #hello.pl use strict; print "Hello! I wrote my first perl script!!\n";
Running the script and the output:
%% ./hello.pl Hello! I wrote my first perl script!!
- Write your first perl scirpt
- use the format described above
- use the print funtion