Introduction to Perl Bioinformatics What is Perl n
Introduction to Perl Bioinformatics
What is Perl? n n n Practical Extraction and Report Language A scripting language Components n n an interpreter scripts: text files created by user describing a sequence of steps to be performed by the interpreter
Installation n n Create a Perl directory under C: Either n n n Download AP. msi from the course website (http: //curry. ateneo. net/~jpv/Bioinf) and execute (installs into C: Perl directory) Or download and unzip AP. zip into C: Perl Reset path variable first (or edit C: autoexec. bat) so that you can execute scripts from MSDOS n C> path=%path%; c: Perlbin
Writing and Running Perl Scripts n Create/edit script (extension: . pl) n C> edit first. pl # my first script print “Hello World”; print “this is my first script”; n Execute script n C> perl first. pl * Tip: place your scripts in a separate work directory
Perl Features n n n n n Statements Strings Numbers and Computation Variables and Interpolation Input and Output Files Conditions and Loops Pattern Matching Arrays and Lists
Statements n n A Perl script is a sequence of statements Examples of statements print “Type in a value”; $value = <>; $square = $value * $value; print “The square is ”, $square, “n”;
Comments n Lines that start with # are ignored by the Perl interpreter # this is a comment line n In a line, characters that follow # are also ignored $count = $count + 1; # increment $count
Strings n String n n n In Perl, characters should be surrounded by quotes n n n Sequence of characters Text ‘I am a string’ “I am a string” Special characters specified through escape sequences (preceded by a ) n “a newlinen and a tabt”
Numbers n Integers specified as a sequence of digits n n n 6 453 Decimal numbers: n n 33. 2 6. 04 E 24 (scientific notation)
Variables n n n Variable: named storage for values (such as strings and numbers) Names preceded by a $ Sample use: $count = 5; # assignment statement $message = “Hello”; # another assignment print $count; # print the value of a variable
Computation n Fundamental arithmetic operations: n n Others n n n +-*/ ** exponentiation () grouping Example (try this out as a Perl script) $x = 4; $y = 2; $z = (3 + $x) ** $y; print $z, “n”;
Interpolation n Given the following script: $x = “Smith”; print “Good morning, Mr. $x”; print ‘Good morning, Mr. $x’; n Strings quoted with “” perform expansions on variables
Input and Output
Files
Conditions
Loops
Pattern Matching
Arrays and Lists
- Slides: 18