Lesson 1: Perl script skeleton


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.

  1. path to perl
    • 1
      
      #!/usr/bin/perl
    • This can differ on different systems, or if you have a local or nonstandard installation of perl.
  2. allow for extensive reporting of warnings
    • 2
      
      #!/usr/bin/perl -w
  3. use the strict module
    • 3
      
      use strict;
    • using the strict library will help you to keep track of variable names and scope
  4. add comments
    • 4
      
      #hello.pl
    • 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
  5. the body of you script that does something.
    • 5
      
      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.

  1. 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
  2. running it from the commmand line
    • %% ./hello.pl

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!!

Exercises

  1. Write your first perl scirpt
    • use the format described above
    • use the print funtion

Print Friendly

2 thoughts on “Lesson 1: Perl script skeleton

  1. Is there a way to create/download a PDF file of the entire tutorial? When I selected PDF from the main page I ended up with a PDF file containing only the table of contents. I’d like to be able to read through the material in a place that has no internet connectivity.

Leave a Reply

Your email address will not be published. Required fields are marked *