P ractical  E xtraction and R eport  L anguage
Perl <ul><li>freeware and OpenSource scripting language </li></ul><ul><li>original author Larry Wall, contributions from m...
Perl <ul><li>Perl version 5 allows for object-oriented programming </li></ul><ul><li>BioPerl : collection of libraries for...
Perl : recommended literature <ul><li>Larry Wall, Tom Christiansen & Jon Orwant : Programming Perl (3rd edition, Covers Pe...
Perl : syntax <ul><li>print 3 + 5 </li></ul><ul><li>will write   8   on the screen </li></ul><ul><li>print '3 + 5' </li></...
Perl : syntax <ul><li>$var = '3 + 5'; </li></ul><ul><li>if ($var eq '3 + 5') { print 'it is' }; </li></ul><ul><li>will wri...
Perl : lists <ul><li>foreach $x (a, b, c) { </li></ul><ul><li>print $x; </li></ul><ul><li>print '_'; </li></ul><ul><li>} <...
Perl : arrays  <ul><li>@list = (a, b, c); </li></ul><ul><li>foreach $x (@list) </li></ul><ul><li>{ print $x; print '_'; } ...
<ul><li>$xxx = $yyy . $zzz; </li></ul><ul><li>content variable yyy and variable zzz concatenated and put in variable xxx <...
Perl : hashes <ul><li>key  value </li></ul><ul><li>%day = ('Monday'  => 1, </li></ul><ul><li>'Thuesday'  => 2, </li></ul><...
The concept of object-oriented programming <ul><li>An  object  belongs to a  class , an individual object is said to be an...
Objects under Perl <ul><li>package Circle; </li></ul><ul><li>bla bla bla </li></ul><ul><li>... </li></ul><ul><li>definitio...
Upcoming SlideShare
Loading in …5
×

Very gentle handson introduction to Perl

1,124 views

Published on

These are the lecture slides for the BITS training session on perl programming.

See for more information: http://www.bits.vib.be/index.php?option=com_content&view=article&id=17203785:gray-hands-on-introduction-to-perl-programming&catid=81:training-pages&Itemid=190

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,124
On SlideShare
0
From Embeds
0
Number of Embeds
134
Actions
Shares
0
Downloads
18
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Very gentle handson introduction to Perl

  1. 1. P ractical E xtraction and R eport L anguage
  2. 2. Perl <ul><li>freeware and OpenSource scripting language </li></ul><ul><li>original author Larry Wall, contributions from many volunteers </li></ul><ul><li>Perl interpreter available as source code in C and as executable for Windows, Linux and MacOS X </li></ul><ul><li>Perl makes easy things easy and difficult things possible </li></ul><ul><li>Perl syntax rich and flexible ( There's more than one way to do it ), much of it borrowed from C, sed, awk and UNIX shell </li></ul>
  3. 3. Perl <ul><li>Perl version 5 allows for object-oriented programming </li></ul><ul><li>BioPerl : collection of libraries for writing scripts for molecular biology </li></ul><ul><li>Sanger Centre genome annotation pipeline originally written in Perl </li></ul><ul><li>Several software suites, databases and bioinformatic service centres provide API in (Bio)Perl </li></ul><ul><li>cpan Perl program allows for automated installation of Perl packages, taking care of the dependencies. </li></ul>
  4. 4. Perl : recommended literature <ul><li>Larry Wall, Tom Christiansen & Jon Orwant : Programming Perl (3rd edition, Covers Perl 5.6). (O'Reilly & Associates, 2000, ISBN 0-596-00027-8|978-0-596-00027-1) </li></ul><ul><li>James Tisdall : Beginning Perl for Bioinformatics. (O'Reilly & Associates, 2001, ISBN 0-596-00080-4|978-0-596-00080-6) </li></ul><ul><li>James Tisdall : Mastering Perl for Bioinformatics. (O'Reilly & Associates, 2003, ISBN 0-596-00307-2|978-0-596-00307-4) </li></ul>
  5. 5. Perl : syntax <ul><li>print 3 + 5 </li></ul><ul><li>will write 8 on the screen </li></ul><ul><li>print '3 + 5' </li></ul><ul><li>will write 3 + 5 on the screen </li></ul><ul><li>$var = 3 + 5; </li></ul><ul><li>print $var; </li></ul><ul><li>will write 8 on the screen </li></ul><ul><li>$var = '3 + 5'; </li></ul><ul><li>print $var; </li></ul><ul><li>will write 3 + 5 on the screen </li></ul>
  6. 6. Perl : syntax <ul><li>$var = '3 + 5'; </li></ul><ul><li>if ($var eq '3 + 5') { print 'it is' }; </li></ul><ul><li>will write it is on the screen </li></ul><ul><li>$var = '3 + 5'; </li></ul><ul><li>if ($var == 8) { print 'it is' }; </li></ul><ul><li>will also write it is on the screen </li></ul><ul><li>$var = 3 + 5; </li></ul><ul><li>if ($var eq '3 + 5') { print 'it is' } </li></ul><ul><li>else { print 'it is not'} </li></ul><ul><li>will write it is not on the screen </li></ul>
  7. 7. Perl : lists <ul><li>foreach $x (a, b, c) { </li></ul><ul><li>print $x; </li></ul><ul><li>print '_'; </li></ul><ul><li>} </li></ul><ul><li>will print a_b_c_ </li></ul><ul><li>($x, $y, $z) = (a, b, c); </li></ul><ul><li>print $y; </li></ul><ul><li>will print b </li></ul>
  8. 8. Perl : arrays <ul><li>@list = (a, b, c); </li></ul><ul><li>foreach $x (@list) </li></ul><ul><li>{ print $x; print '_'; } </li></ul><ul><li>will print a_b_c_ </li></ul><ul><li>0 1 2 </li></ul><ul><li>@list = (a, b, c); </li></ul><ul><li>print $list[2]; </li></ul><ul><li>will print c </li></ul>
  9. 9. <ul><li>$xxx = $yyy . $zzz; </li></ul><ul><li>content variable yyy and variable zzz concatenated and put in variable xxx </li></ul><ul><li>$xxx = $xxx . $yyy; </li></ul><ul><li>$xxx .= $yyy; </li></ul><ul><li>(both do the same) </li></ul><ul><li>while ($xxx =~ /yyy/g) { </li></ul><ul><li>$zzz = pos $xxx; </li></ul><ul><li>} </li></ul><ul><li>for as many times as string in variable xxx matches regular expression yyy position first character of match is put in variable zzz </li></ul>Tips for the exercises
  10. 10. Perl : hashes <ul><li>key value </li></ul><ul><li>%day = ('Monday' => 1, </li></ul><ul><li>'Thuesday' => 2, </li></ul><ul><li>'Wednesday' => 3, </li></ul><ul><li>'Thursday' => 4, </li></ul><ul><li>'Friday' => 5, </li></ul><ul><li>'Saterday' => 6, </li></ul><ul><li>'Sunday' => 7); </li></ul><ul><li>print $day{'Wednesday'}; </li></ul><ul><li>will print 3 </li></ul>
  11. 11. The concept of object-oriented programming <ul><li>An object belongs to a class , an individual object is said to be an instance of the class </li></ul><ul><li>An object has attributes , which are themselves simple variables or objects </li></ul><ul><li>An object has methods , wich are actually subroutines ; a creator method creates a new object, an instance method operates on an individual object </li></ul><ul><li>In some languages a class can inherit from one (single inheritance) or several (multiplt inheritance) classes, with this is it gets all their attribute and method definitions </li></ul>
  12. 12. Objects under Perl <ul><li>package Circle; </li></ul><ul><li>bla bla bla </li></ul><ul><li>... </li></ul><ul><li>definition of class Circle + some code to make it work </li></ul><ul><li>$mycircle = Circle->new(5); </li></ul><ul><li>creation of new object called $mycircle , which is a circle with radius of 5 units </li></ul><ul><li>$mycircle->draw; </li></ul><ul><li>$mycircle will draw itself on the screen </li></ul>

×