What is PERL?

Similar documents
PERL - FUNCTIONS REFERENCES

1. Introduction. 2. Scalar Data

Pathologically Eclectic Rubbish Lister

Scripting Languages Perl Basics. Course: Hebrew University

Introduction to Perl. Perl Background. Sept 24, 2007 Class Meeting 6

Perl. Interview Questions and Answers

CSCI 4152/6509 Natural Language Processing. Perl Tutorial CSCI 4152/6509. CSCI 4152/6509, Perl Tutorial 1

8/13/ /printqp.php?heading=II BSc [ ], Semester III, Allied: COMPUTER PROGRAMMING-PERL -309C&qname=309C

Sequence Analysis with Perl. Unix, Perl and BioPerl. Why Perl? Objectives. A first Perl program. Perl Input/Output. II: Sequence Analysis with Perl

Bioinformatics. Computational Methods II: Sequence Analysis with Perl. George Bell WIBR Biocomputing Group

Unix, Perl and BioPerl

Welcome to Research Computing Services training week! November 14-17, 2011

Outline. CS3157: Advanced Programming. Feedback from last class. Last plug

(Refer Slide Time: 01:12)

PERL Scripting - Course Contents

Beginning Perl. Mark Senn. September 11, 2007

They grow as needed, and may be made to shrink. Officially, a Perl array is a variable whose value is a list.

9.1 Origins and Uses of Perl

15.1 Origins and Uses of Ruby

COMS 3101 Programming Languages: Perl. Lecture 2

T-( )-MALV, Natural Language Processing The programming language Perl

Regular expressions and case insensitivity

Programming Perls* Objective: To introduce students to the perl language.

Perl Scripting. Students Will Learn. Course Description. Duration: 4 Days. Price: $2295

CSCI-GA Scripting Languages

Indian Institute of Technology Kharagpur. PERL Part II. Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. I.I.T.

Bamuengine.com. Chapter 14. Perl The Mater Manipulator

Scripting Languages. Diana Trandabăț

More Perl. CS174 Chris Pollett Oct 25, 2006.

Perl for Biologists. Session 2 March 19, Constants, variables and functions. Jaroslaw Pillardy

CMSC 331 Final Exam Fall 2013

Hands-On Perl Scripting and CGI Programming

behavior of objects, 429 of variables, defining, 494

Appendix B WORKSHOP. SYS-ED/ Computer Education Techniques, Inc.

PERL Bioinformatics. Nicholas E. Navin, Ph.D. Department of Genetics Department of Bioinformatics. TA: Dr. Yong Wang

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

autodie - Replace functions with ones that succeed or die with lexical scope # Recommended: implies 'use autodie qw(:default)'

Indian Institute of Technology Kharagpur. PERL Part III. Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. I.I.T.

Introduc)on to Unix and Perl programming

Regular expressions and case insensitivity

CSc 372. Comparative Programming Languages. 4 : Haskell Basics. Department of Computer Science University of Arizona

Introduc)on to Unix and Perl programming

CSc 372 Comparative Programming Languages. 4 : Haskell Basics

UNIX Shell Programming

Perl and Python ESA 2007/2008. Eelco Schatborn 27 September 2007

IT441. Network Services Administration. Perl: File Handles

COMP284 Scripting Languages Lecture 3: Perl (Part 2) Handouts

Lecture 2: Programming in Perl: Introduction 1

Tieing and Overloading Objects in Perl. Dave Cross Magnum Solutions

CSC Web Programming. Introduction to JavaScript

UNIT- 3 Introduction to C++

Introduction to Perl. c Sanjiv K. Bhatia. Department of Mathematics & Computer Science University of Missouri St. Louis St.

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

CS 230 Programming Languages

Perl (5 Days Content)

Programming introduction part I:

Introductory Perl. What is Perl?

Sprite an animation manipulation language Language Reference Manual

Computational Theory MAT542 (Computational Methods in Genomics) - Part 2 & 3 -

Client-Side Web Technologies. JavaScript Part I

Perl Basics 7 Mar 2009 #fedora-classroom. Doran Barton

2. Numbers In, Numbers Out

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

A control expression must evaluate to a value that can be interpreted as true or false.

C: How to Program. Week /Mar/05

print STDERR "This is a debugging message.\n";

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.

Advanced Web Design. Unit 8 The Basics of Perl

Chapter 1 Introduction to Computers and C++ Programming

Examples of Using the ARGV Array. Loop Control Operators. Next Operator. Last Operator. Perl has three loop control operators.

Overview: Programming Concepts. Programming Concepts. Names, Values, And Variables

Overview: Programming Concepts. Programming Concepts. Chapter 18: Get With the Program: Fundamental Concepts Expressed in JavaScript

Bash scripting. Can put together bash commands into one big file to run all at once! CIS c. 22/02/09 Slide 1

PERL. Pattern Extraction and Reporting Language. Example: $x = 10 $value = $x + 1 $word = "hello"

what are strings today: strings strings: output strings: declaring and initializing what are strings and why to use them reading: textbook chapter 8

Chapter 2 - Introduction to C Programming

CS Summer 2013

Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University

Course Outline Introduction to C-Programming

C Language Part 1 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

Introduction to C++ Programming Pearson Education, Inc. All rights reserved.

MATLAB Constants, Variables & Expression. 9/12/2015 By: Nafees Ahmed

Perl Tutorial. Diana Inkpen. School of Information Technology and Engineering University of Ottawa. CSI 5180, Fall 2004

Reserved Words and Identifiers

IT 374 C# and Applications/ IT695 C# Data Structures

9/5/2018. Overview. The C Programming Language. Transitioning to C from Python. Why C? Hello, world! Programming in C

Operators. Java operators are classified into three categories:

CS 106 Introduction to Computer Science I

The C Programming Language. (with material from Dr. Bin Ren, William & Mary Computer Science)

These are reserved words of the C language. For example int, float, if, else, for, while etc.

Lecture 12. PHP. cp476 PHP

EVALUATION COPY. Module Table of Contents

Chapter 4. Programming in Perl. 4.1 More on built-in functions in Perl split and join (+ qw, x operator, here docs,.=)

Programming for Engineers Arrays

C++ Basics. Lecture 2 COP 3014 Spring January 8, 2018

Course Outline. Introduction to java

2. Numbers In, Numbers Out

Full file at C How to Program, 6/e Multiple Choice Test Bank

Copyright 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Chapter 11 Introduction to PHP

Introduction to Perl Session 6. special variables subroutines Introduction to Perl

Transcription:

Perl For Beginners

What is PERL? Practical Extraction Reporting Language General-purpose programming language Creation of Larry Wall 1987 Maintained by a community of developers Free/Open Source www.cpan.org

Why use Perl? Perl is fast, especially at common tasks in biology: file manipulation and pattern matching Good at manipulating large data sets or performing the same task repeatedly CGI module gives simple interface for delivering dynamic web pages DBI modules provide database-independent interface for Perl Powerful easy-to-use modules for network programming (Web, E-Mail, FTP, etc.) TMTOWTDI

Overview Scalars, scalar variables and operations Control blocks and conditions Array, array variables and array operations Tips and resources

The Basics Text file using ordinary text editor (nedit, emacs) Comments begin with a pound-sign (#) Statements end with semi-colon (;) White space independent Case sensitive Variables need not be declared or typed

Scalars Represent a single piece of data Can represent string or numeric 2, 3.1456, 1e-27, ATC, NM_000327 Scalar Variables Variable names consist of a dollar sign ($) followed by a letter or underscore then followed by zero or more letters, digits or underscores $name, $old_name Used to hold results of calculations, constants, input from keyboard, files, etc $acc_number = NM_000327 ;

Numeric Operators Addition (+), subtraction (-), multiplication (*), division (/), modulus(%), exponentiation (**) $a=1; $b=2; $c=$a + $b; # $c equals 3 $d=$c**2; # $d equals $c to the power of 2 which is 9 $e=$d%2; # $e equals the remainder of 9/2 which is 1

Numeric Comparison Operators == (equality),!= (inequality), >(greater than), >=(greater than or equal to), < (less than), <= (less than or equal to) $a=1; $b=2; $a==$b # false $a!= $b # true $b >= $a # true

String Operators. (concatenation), eq (equality), ne(inequality) $a = Hello ; $b = $a. World ; # $b equals Hello World $a eq Hello ; # evaluates to true $a ne World ; # also evaluates to true

Variable Interpolation Variables are interpolated within double quotes but not within single quotes $a = student ; hello $a ; # evaluates to hello student hello $a ; # evaluates to hello $a New lines (\n), tabs (\t) and other special characters interpolated within double quotes print hello\tstudent\twelcome\tto\boston\n ; prints tabs between each word and a trailing new line

Statements Blocks Curly Braces surrounding multiple statements # this is a naked block { Statement 1; Statement 2; } Naked block has no effect on program flow Blocks are typically part of a larger construct Types: while, for, foreach, if/else

if/elsif/else if (test_expression) { Statement 1; Statement 2; } elsif (test_expression2) { Statement 3; } else { Statement 4; } Statement 1 and 2 are executed if test_expression is true, Statement 3 is excuted if test_expression2 is true, otherwise statement 4 is executed

More on if/else Braces are required (unlike other languages) else is optional unless can be used instead of if which reverses the test If more than two conditions exist use elsif

Arrays List of scalars Can store heterogeneous information No space allocation. Expands as necessary Ordered sequentially and indexed (start at 0) Variable names start with @ @bases = ( A, T, G, C ); 0 1 2 3 # index

Array Assignments @a = (7.34, coffee, tea, 343); qw - use white space to separate elements @a = qw (7.34 coffee tea 343); Can be made up of scalar and array variables @bases=qw(a T G C); $a = N ; @legal_bases = (@bases, $a, X ) # ATGCNX

Accessing Array Elements An array element can be retrieved by accessing its index @bases = qw (A C T G); $third_base = $bases[2]; # $third_base equals T Elements can also be modified this way $bases[3]= X ; # @bases now (A C T X) Negative subscripts count backward $bases[-1]; #refers to last element X @bases and $bases are completely different

Filehandles To read from or write to a file in Perl, it first needs to be opened. In general, open (filehandle, filename); Filehandles can serve at least three purposes: open (IN, $file); # Open for input open (OUT, >$file ); # Open for output open (OUT, >>$file ); #Open for appending Then, get data all at once @lines =<IN>; Or one line at a time while (<IN>){ $line = $_ # do stuff with this line Print OUT This line: $line ;

Perl Functions Functions for scalars or strings chomp, chop, chr, crypt, hex, index, lc, lcfirst, length, oct, ord, pack, q/ STRING/, qq/string/, reverse, rindex, sprintf, substr, tr///, uc, ucfirst, y/// Regular expressions and pattern matching m//, pos, quotemeta, s///, split, study, qr// Numeric functions abs, atan2, cos, exp, hex, int, log, oct, rand, sin, sqrt, srand Functions for real @ARRAYs pop, push, shift, splice, unshift Functions for list data grep, join, map, qw/string/, reverse, sort, unpack Input and output functions binmode, close, closedir, dbmclose, dbmopen, die, eof, fileno, flock, format, getc, print, printf, read, readdir, rewinddir, seek, seekdir, select, syscall, sysread, sysseek, syswrite, tell, telldir, truncate, warn, write

Chop and Chomp Chop Removes the last character of a string $a = testing 123 ; chop $a; # $a now equals testing 12 Chomp Removes the last character of a string only if it is a newline (/n) $b = this is a test\n ; chomp $b; # $b now equals this is a test

Pop and Push Pop Removes and returns the last value of the array Push Adds elements to the end of the array @bases = qw(a C T G); $z = pop @bases; #$z is G and @bases is (A C T) @a = (4, 5, 6, 7); push @a, 8; #@a is now (4, 5, 6, 7, 8)

Shift and Unshift Shift Removes and returns the first element off the array Unshift Adds elements to the beginning of an array @n = (9,8,7,6); $a = shift @n; # $a equals 9, @n = (8,7,6); @y = (25, 26, 27); Unshift @y, 24; # @y becomes (24, 25, 26, 27)

Resources http://learn.perl.org/ http://www.oreilly.com/ BaRC Library Unix-Perl course Spring 2005 http://jura.wi.mit.edu/bio/education/ bioinfo2005/unix-perl/ Perl Library http://iona.wi.mit.edu/bio/ bioinfo/scripts/