Introduction to Perl Giorgos Georgakilas Graduated from C.E.I.D.Graduated from C.E.I.D. M.Sc. degree in ITMBM.Sc. degree in ITMB Ph.D. student in DIANA-LabPh.D.

Slides:



Advertisements
Similar presentations
Perl Practical Extration and Reporting Language An Introduction by Shwen Ho.
Advertisements

JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
A Guide to Unix Using Linux Fourth Edition
Introduction to Unix – CS 21 Lecture 11. Lecture Overview Shell Programming Variable Discussion Command line parameters Arithmetic Discussion Control.
Second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Master Manipulator perl Perl is.
Bioinformatics is … - the use of computers and information technology to assist biological studies - a multi-dimensional and multi-lingual discipline Chapters.
Programming Perls* Objective: To introduce students to the perl language. –Perl is a language for getting your job done. –Making Easy Things Easy & Hard.
CSET4100 – Fall 2009 Perl Introduction Scalar Data, Operators & Control Blocks Acknowledgements: Slides adapted from NYU Computer Science course on UNIX.
Programming and Perl for Bioinformatics Part I. A Taste of Perl: print a message perltaste.pl: Greet the entire world. #!/usr/bin/perl #greet the entire.
CS311 – Today's class Perl – Practical Extraction Report Language. Assignment 2 discussion Lecture 071CS Operating Systems I.
Scripting Languages Chapter 6 I/O Basics. Input from STDIN We’ve been doing so with $line = chomp($line); Same as chomp($line= ); line input op gives.
Practical Extraction & Report Language Picture taken from
Perl Basics A Perl Tutorial NLP Course What is Perl?  Practical Extraction and Report Language  Interpreted Language Optimized for String Manipulation.
Bash, part 2 Prof. Chris GauthierDickey COMP Unix Tools.
Perl Lecture #1 Scripting Languages Fall Perl Practical Extraction and Report Language -created by Larry Wall -- mid – 1980’s –needed a quick language.
CS 898N – Advanced World Wide Web Technologies Lecture 7: PERL Chin-Chih Chang
Guide To UNIX Using Linux Third Edition
2.1 Lists and Arrays Summary of 1 st lesson Single quoted and double quoted strings Backslash ( \ ) – the escape character: \t \n Operators:
2ex.1 Lists and Arrays. 2ex.2 Comments on exercises Always run your script with “ perl -w ” and take care of all warnings  submitted scripts should not.
PHP Server-side Programming. PHP  PHP stands for PHP: Hypertext Preprocessor  PHP is interpreted  PHP code is embedded into HTML code  interpreter.
Introduction to Perl Part I By: Cédric Notredame (Adapted from BT McInnes)
Introduction to Perl Practical Extraction and Report Language or Pathologically Eclectic Rubbish Lister or …
Introduction to Perl & BioPerl Dr G. P. S. Raghava Bioinformatics Centre Bioinformatics Centre IMTECH, Chandigarh Web:
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
1 Perl Perl basics Perl Elements Arrays and Hashes Control statements Operators OOP in Perl.
1 An Introduction to Perl Part 1 CSC8304 – Computing Environments for Bioinformatics - Lecture 7.
Perl Tutorial Presented by Pradeepsunder. Why PERL ???  Practical extraction and report language  Similar to shell script but lot easier and more powerful.
Perl By Gabe and Ted. History Perl was created by Larry Wall while working at NASA’s Jet Propulsion Labs. Larry Wall also created patch which is in widespread.
1 System Administration Introduction to Scripting, Perl Session 3 – Sat 10 Nov 2007 References:  chapter 1, The Unix Programming Environment, Kernighan.
Perl Practical(?)‏ Extraction and Report Language.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
JavaScript Syntax and Semantics. Slide 2 Lecture Overview Core JavaScript Syntax (I will not review every nuance of the language)
Introduction to Perl Yupu Liang cbio at MSKCC
Books. Perl Perl (Practical Extraction and Report Language) by Larry Wall Perl 1.0 was released to usenet's alt.comp.sources in 1987 Perl 5 was released.
Perl Language Yize Chen CS354. History Perl was designed by Larry Wall in 1987 as a text processing language Perl has revised several times and becomes.
Perl: Lecture 1 The language. What Perl is Merger of Unix tools – Very popular under UNIX – shell, sed, awk Programming language – C syntax Scripting.
Chapter 9: Perl Programming Practical Extraction and Report Language Some materials are taken from Sams Teach Yourself Perl 5 in 21 Days, Second Edition.
Prof. Alfred J Bird, Ph.D., NBCT Office – McCormick 3rd floor 607 Office Hours – Tuesday and.
Computer Programming for Biologists Class 3 Nov 13 th, 2014 Karsten Hokamp
©Colin Jamison 2004 Shell scripting in Linux Colin Jamison.
Perl Tutorial. Why PERL ??? Practical extraction and report language Similar to shell script but lot easier and more powerful Easy availablity All details.
Perl Basics. sh-bang !!!! Every perl program starts with a sh-bang line #!/usr/bin/perl # hello.pl printf “Hello, world!\n”; printf STDOUT “Hello, world!\n”;
Perl Chapter 5 Hashes. Outside of world of Perl, know as associative arrays Also called hash tables Perl one of few languages that has hashes built-in.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
Getting started in Perl: Intro to Perl for programmers Matthew Heusser – xndev.com - Presented to the West Michigan Perl User’s Group.
Perl COEN 351  Thomas Schwarz, S.J Perl Scripting Language Developed by Larry Wall 1987 to speed up system administration tasks. Design principles.
Introduction to Perl October 4, 2004 Class Meeting 7 * Notes on Perl by Lenwood Heath, Virginia Tech © 2004.
Introduction to Perl NICOLE VECERE. Background General Purpose Language ◦ Procedural, Functional, and Object-oriented Developed for text manipulation.
Department of Electrical and Computer Engineering Introduction to Perl By Hector M Lugo-Cordero August 26, 2008.
Introduction to Perl. What is Perl Perl is an interpreted language. This means you run it through an interpreter, not a compiler. Similar to shell script.
Basic Variables & Operators Web Programming1. Review: Perl Basics Syntax ► Comments: start with # (ignored by Perl) ► Statements: ends with ; (performed.
Perl Variables: Array Web Programming1. Review: Perl Variables Scalar ► e.g. $var1 = “Mary”; $var2= 1; ► holds number, character, string Array ► e.g.
Perl Scripting III Arrays and Hashes (Also known as Data Structures) Ed Lee & Suzi Lewis Genome Informatics.
2.1 Scalar data - revision numeric e-14 ( = 6.35 × )‏ operators: + (addition) - (subtraction) * (multiplication) / (division)
 History  Ease of use  Portability  Standard  Security & Privacy  User support  Application &Popularity Today  Ten Most Popular Programming Languages.
PERL By C. Shing ITEC Dept Radford University. Objectives Understand the history Understand constants and variables Understand operators Understand control.
CSI605 perl. Perl Facts Perl = Pathologically Eclectic Rubbish Lister Perl is highly portable across many different platforms and operating systems Perl.
Dept. of Animal Breeding and Genetics Programming basics & introduction to PERL Mats Pettersson.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
Operators. Perl has MANY operators. –Covered in Chapter 3 of Camel –perldoc perlop Many operators have numeric and string version –remember Perl will.
Organization of Programming Languages Meeting 37 April 18, 2016.
PHP using MySQL Database for Web Development (part II)
JavaScript Syntax and Semantics
Perl Variables: Array Web Programming.
Control Structures: if Conditional
An Introduction to Perl
Programming Perls* Objective: To introduce students to the perl language. Perl is a language for getting your job done. Making Easy Things Easy & Hard.
PHP an introduction.
INTRODUCTION to PERL PART 1.
Presentation transcript:

Introduction to Perl Giorgos Georgakilas Graduated from C.E.I.D.Graduated from C.E.I.D. M.Sc. degree in ITMBM.Sc. degree in ITMB Ph.D. student in DIANA-LabPh.D. student in DIANA-Lab Perl>

What is Perl? Perl is a Portable Scripting LanguagePerl is a Portable Scripting Language No compiling is needed.No compiling is needed. Runs on UNIX, Linux, MacOS and WindowsRuns on UNIX, Linux, MacOS and Windows Fast and easy text processing capabilityFast and easy text processing capability Flexible syntaxFlexible syntax Flexible data structuresFlexible data structures “Perl is the language for getting your job done.”“Perl is the language for getting your job done.” Larry Wall

How to Access Perl Perl comes by default on Linux, Cygwin, MacOSXPerl comes by default on Linux, Cygwin, MacOSX 1.kwrite 2.kate (the best!) A good implementation for windows is Strawberry perlA good implementation for windows is Strawberry perl 1.notepad++ To check if Perl is working and the version numberTo check if Perl is working and the version number >perl –v

Perl programs always start with the line: #!/bin/perlPerl programs always start with the line: #!/bin/perl The next 2 lines should always be:The next 2 lines should always be: use warnings; use strict; So let's see a first listing:So let's see a first listing:#!/bin/perl #This is a Perl comment! use warnings; use strict; print "Hello world\n"; Hello perl helloWorld.pl Perl Basics

Perl supports all the basic arithmetic functions: Double quotes interpret special characters like \n, \tDouble quotes interpret special characters like \n, \t print "5 * 2 = ", 5 * 2, "\n"; print "5 + 2 = ", 5 + 2, "\n"; warn "5 - 2 = ", 5 - 2, "\n"; print "5 squared = ", 5 ** 2, "\n"; print "5 mod 2 = ", 5 % 2, "\n"; Single quotes treat the contents literally:Single quotes treat the contents literally: print '5 * 2 = ', 5 * 2, '\n'; Print formatted strings, like in C.Print formatted strings, like in C. printf ("7 / 3 = %4.2f\n", 7/3); Get data from keyboardGet data from keyboardgetc(); Perl Basics

To declare and initiate a scalar variable, use the syntax:To declare and initiate a scalar variable, use the syntax: my $var = 15; ## an integer my $var2 = 1.5; ## a float my $var3 = "hello"; ## a string my $var3 = 'a'; ## a character my ($var4, $var5, $var6) = (1,2,3); ## define several at once. ($var4, $var5) = ($var5, $var4); ## a useful way to swap 2 values. You can also suppress interpolation with a backslash.You can also suppress interpolation with a backslash. print "\$var * \$var2 = ", $var * $var2, "\n"; Scalars

Perl Basics To test for definition:To test for definition: if (defined ($var1)) {... To test for truth:To test for truth: if ($var1) {... To test for falsity:To test for falsity: if (!$var1) {... StatusMeaningExample exists Variable has been declared but has no value my $var1; defined Variable has a value, which may be true or false my $var1 = 0; #false NumbersStrings>gt <lt ==eq !=ne <=le >=ge Variable Status & Conditional expressions

Perl Basics Strings my $string = "atcgtagctagctgc"; Get length of stringGet length of string print "$string has ", length($string), " characters\n"; Reverse a stringReverse a string my $reversed = reverse($string); print "$string reversed is $reversed\n"; Concatenate strings using '.'Concatenate strings using '.' my $palindrome = $string. $reversed; print "\$palindrome is $palindrome \n"; Get a substring...Get a substring... print "1st 6 letters of $string are ", substr($string, 0, 6), "\n"; print "last 6 letters of $string are ", substr($string, -6, 6), "\n";

Perl Basics Arrays A Perl array is simply a list of Perl scalars and is a core data type in Perl. = (1, 2, 3, 4, 5); = ("string1", "string2", "string3");A Perl array is simply a list of Perl scalars and is a core data type in Perl. = (1, 2, 3, 4, 5); = ("string1", "string2", "string3"); Using the 'qw' operator just removes the need for quotes around strings: = qw(string1 string2 string3);Using the 'qw' operator just removes the need for quotes around strings: = qw(string1 string2 string3); Arrays resize automatically as required. To access an element we use the syntax: my $first_el = $array1[0];Arrays resize automatically as required. To access an element we use the syntax: my $first_el = $array1[0]; Let's examine some useful things we can do with arrays.Let's examine some useful things we can do with arrays. my $stringing = "atcgtagctagctgc"; = ( 1, 2, 3, 4, 5, 6, 7); = ("a", "b", "c", "d"); To convert an array to a string, use 'join‘To convert an array to a string, use 'join‘ my $string = join print " joined array is $string\n";

Perl Basics Arrays Add /remove elements to/from the start of the array..Add /remove elements to/from the start of the array.. "new_1st_element"; print " after unshifting, is ", my $new_1st_element = And the endAnd the end "e"; print " after pushing, is ". print " after popping, is ". To get length of array use get length of array use print contains ", elements\n"; Array resizes automaticallyArray resizes automatically $str[500] =56; print now contains ", elements\n";

Perl Basics Loops The usual…The usual… for (my $i = 0; $i < 10; $i++) { code} If you're looping over every element in an array you can writeIf you're looping over every element in an array you can write for my $i { code} foreach { if ($_ > 4)....} 'sort' creates a sorted array. By default it sorts in ascending order.'sort' creates a sorted array. By default it sorts in ascending order. = print is ", join "\n\n"; E.g., sort the strings alphabetically by their last letter.E.g., sort the strings alphabetically by their last letter. = ("adf", "bde", "crt", "dra"); = sort{substr($a, -1, 1) cmp substr($b, -1, print is ", join "\n"; To execute while statements is very similar to other languages:To execute while statements is very similar to other languages: while ($i >0){ do something} As is the do..while statement:As is the do..while statement: do { something at least once }while ($i > 0 );

Perl Basics Hashes To declare a hashTo declare a hash my %hash = (key1 => 1, key2 => 2, key3 =>3 ); my $v1 = $hash{'key1'}; $hash{'key1'} = "new value"; To get all the keys in the hash use “keys”To get all the keys in the hash use “keys” = keys %hash; delete $hash{'key1'}; if(exists( $hash{'key1'} ) ){...}; To iterate through the hash, iterate through the keys:To iterate through the hash, iterate through the keys: for my $key (keys %hash) {print "$hash{$key}\n";} Sort keys before retrieving valuesSort keys before retrieving values for my $key ( sort keys %hash) {print "$hash{$key}\n";}

Web Sources for Perl