Perl Basics Why Perl for data processing & bioinformatics - Fast text processing - Regular expressions - Extensive module libraries for pre-written tools - Large number of users in community of bioinformatics - Scripts are often faster to write than full compiled programs Every perl script needs to contain the following line: #!/usr/bin/perl use warnings; use strict; Print "hello world". Type this into your text editor and save it. Give the script a .pl extension. #!/usr/bin/perl use warnings; print "hello world\n"; Run it: on the command line type perl your_script_name.pl Try it without a new line character (\n). Using variables: $scalar A scalar contains a value, can be a string or a number. @array An array contains a list of values. %hash A hash contains paired values (key/value pairs) Using a scalar to print: #!/usr/bin/perl use warnings; $phrase = "hello world"; print "$phrase\n"; # This is a comment # A print statement can combine variables and strings print "This is my phrase $phrase\n"; # this is another way to print the same as above # the print function takes a list of arguments # in this example "This is my phrase $phrase" is the first argument # and "\n" is the second print "This is my phrase $phrase" , "\n"; Scope: (we will go over this concept in more detail at a later time) use strict; my, use "my" only when declaring a variable, when it is first mentioned. Getting information from the user: #!/usr/bin/perl use warnings; use strict; my $word1 = shift; # the arguments provided on the command line are saved in an # array. shift is a function that "shifts" the first item off of the array. my $word2 = shift; print "$word2\t$word1\n"; # \t is a tab character Something Advanced but fun tr/// #!/usr/bin/perl use warnings; use strict; my $pet = "cat"; print $pet, "\n"; $pet =~ tr/cat/dog/; print $pet , "\n"; $pet =~ tr/o/O/; print $pet, "\n"; dOg $pet =~ tr/gd/wc/; print $pet, "\n"; Documentation of perl scripts and modules Perldoc online http://perldoc.perl.org/ Or on your computer - type 'perldoc' For functions use -f 'perldoc -f sprintf' For modules just the name 'perldoc List::Util' http://www.cpan.org Problem Set Create a script called "add.pl" script to sum two $scalar variables: (hint: use + ) Modify this script so that it gets both variables from the command line Create a script to produce the reverse complement of a sequence (hint, use the reverse and tr/// functions) reversec.pl GAGAGAGAGAGTTTTTTTTT output: AAAAAAAAACTCTCTCTCTC