Introduction to Perl Yupu Liang cbio at MSKCC

Slides:



Advertisements
Similar presentations
The Linux Operating System Lecture 6: Perl for the Systems Administrator Tonga Institute of Higher Education.
Advertisements

● Perl reference
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.
CS311 – Today's class Perl – Practical Extraction Report Language. Assignment 2 discussion Lecture 071CS Operating Systems I.
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
Perl Basics A Perl Tutorial NLP Course What is Perl?  Practical Extraction and Report Language  Interpreted Language Optimized for String Manipulation.
Perl Lecture #1 Scripting Languages Fall Perl Practical Extraction and Report Language -created by Larry Wall -- mid – 1980’s –needed a quick language.
Guide To UNIX Using Linux Third Edition
Guide To UNIX Using Linux Third Edition
Introduction to Unix (CA263) Introduction to Shell Script Programming By Tariq Ibn Aziz.
Introduction to Linux and Shell Scripting Jacob Chan.
Computer Programming for Biologists Class 2 Oct 31 st, 2014 Karsten Hokamp
Introduction to Shell Script Programming
1 Operating Systems Lecture 3 Shell Scripts. 2 Brief review of unix1.txt n Glob Construct (metacharacters) and other special characters F ?, *, [] F Ex.
Introduction to Perl Practical Extraction and Report Language or Pathologically Eclectic Rubbish Lister or …
8 Shell Programming Mauro Jaskelioff. Introduction Environment variables –How to use and assign them –Your PATH variable Introduction to shell programming.
Introduction to Perl & BioPerl Dr G. P. S. Raghava Bioinformatics Centre Bioinformatics Centre IMTECH, Chandigarh Web:
1 Perl Perl basics Perl Elements Arrays and Hashes Control statements Operators OOP in Perl.
Perl Tutorial Presented by Pradeepsunder. Why PERL ???  Practical extraction and report language  Similar to shell script but lot easier and more powerful.
Computer Programming for Biologists Oct 30 th – Dec 11 th, 2014 Karsten Hokamp  Fill out.
CS 105 Perl: Course Introduction Nathan Clement 13 May 2014.
Control Structures. Important Semantic Difference In all of these loops we are going to discuss, the braces are ALWAYS REQUIRED. Even if your loop/block.
Course materials may not be reproduced in whole or in part without the prior written permission of IBM. 5.1 © Copyright IBM Corporation 2008 Unit 11: Shell.
1 System Administration Introduction to Scripting, Perl Session 3 – Sat 10 Nov 2007 References:  chapter 1, The Unix Programming Environment, Kernighan.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
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.
7 1 User-Defined Functions CGI/Perl Programming By Diane Zak.
Introduction to Unix – CS 21
Computer Programming for Biologists Class 3 Nov 13 th, 2014 Karsten Hokamp
Introduction to Perl “Practical Extraction and Report Language” “Pathologically Eclectic Rubbish Lister”
Writing Scripts Hadi Otrok COEN 346.
Introducing System Managers to Win32 Perl Programming Tim Christian College of Arts and Sciences Computing Support Services.
Intermediate CGI & CGI.pm Webmaster II - Fort Collins, CO Copyright © XTR Systems, LLC CGI Programming & The CGI.pm Perl Module Instructor: Joseph DiVerdi,
©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.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
Random Bits of Perl None of this stuff is worthy of it’s own lecture, but it’s all a bunch of things you should learn to use Perl well.
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.
CSCI 330 UNIX and Network Programming Unit IX: Shell Scripts.
Scripting Languages Diana Trandab ă ț Master in Computational Linguistics - 1 st year
Chapter 1 Computers, Compilers, & Unix. Overview u Computer hardware u Unix u Computer Languages u Compilers.
A Few More Functions. One more quoting operator qw// Takes a space separated sequence of words, and returns a list of single-quoted words. –no interpolation.
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.
Perl Lab #11 Intro to Perl Debbie Bartlett. Perl Lab #1 2 Perl Practical Extraction and Report Language –or- Pathologically Eclectic Rubbish Lister Created.
Week Four Agenda Link of the week Review week three lab assignment This week’s expected outcomes Next lab assignment Break-out problems Upcoming deadlines.
 History  Ease of use  Portability  Standard  Security & Privacy  User support  Application &Popularity Today  Ten Most Popular Programming Languages.
The Scripting Programming Language
Dept. of Animal Breeding and Genetics Programming basics & introduction to PERL Mats Pettersson.
Introduction to Programming the WWW I CMSC Winter 2003 Lecture 17.
Perl Subroutines User Input Perl on linux Forks and Pipes.
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
Learning Unix/Linux Based on slides from: Eric Bishop.
Week Four Agenda Announcements Link of the week Review week three lab assignment This week’s expected outcomes Next lab assignment Break-out problems.
INTRODUCTION TO SHELL SCRIPTING By Byamukama Frank
Bash Scripting CIRC Summer School 2016 Baowei Liu CIRC Summer School 2016 Baowei Liu.
COMP075 OS2 Bash Scripting. Scripting? BASH provides access to OS functions, like any OS shell Also like any OS shell, BASH includes the ability to write.
Introduction to Perl: Practical extraction and report language
CIRC Winter Boot Camp 2017 Baowei Liu
PERL.
Matlab Training Session 4: Control, Flow and Functions
Programming Basics Web Programming.
Introduction to Programming the WWW I
Introduction to Python
Scratch: selection / branching/ if / If…else / compound conditionals / error trapping by Mr. Clausen.
Programming Perls* Objective: To introduce students to the perl language. Perl is a language for getting your job done. Making Easy Things Easy & Hard.
Presentation transcript:

Introduction to Perl Yupu Liang cbio at MSKCC

what is perl ‘A general-purpose programming language originally developed for text manipulation and now used for a wide range of tasks including system administration, web development, network programming, GUI development, and more.’ Practical Extraction and Report Language And: ‘The language is intended to be PRACTICALl (easy to use, efficient, complete) rather than BEAUTIFUL (tiny, elegant, minimal).’ And Some More: ‘Many earlier computer languages, such as Fortran and C, were designed to make efficient use of expensive computer hardware. In contrast, Perl is designed to make efficient use of expensive computer programmers. Perl has many features that ease the programmer's task at the expense of greater CPU and memory requirements. These include automatic memory management; dynamic typing; strings, lists, and hashes; regular expressions; introspection and an eval() function. Larry Wall was trained as a linguist, and the design of Perl is very much informed by linguistic principles. Examples include Huffman coding (common constructions should be short), good end-weighting (the important information should come first), and a large collection of language primitives. Perl favors language constructs that are natural for humans to read and write, even where they complicate the Perl interpreter.’

Largely for the same reasons other people use perl! Simplify repetitive Why do Biologists Use Perl? Largely for the same reasons other people use perl Relatively easy to learn (and easier to make a mess too). Tones of reusable code exists (bioperl). incredibly flexible coding style (some argues it is too flexible).

How to Use Perl Define the problem Search for existing code Plan your solution Write the code Modify ->Debug ->Modify Run the code

Unix Basic Terminal Directories structure Files

Unix Basics: Commands ‘ls’ - list contents of directory ‘cd’ - change directory ‘pwd’ - path of current directory ‘cp’ - copy ‘mv’ - move ‘more’ - list contents of file ‘touch’ - create empy file ‘chmod’ - change file permission *note, to get detailed help on any command you can usually type ‘man COMMAND’, ‘COMMAND -h’, or ‘COMMAND --help’. *google is very good on finding the right command

Unix Basic: Text Editors Text editors are used to view/create/edit text files You may use any text editor during the course Emacs is a popular choice among perl programmers

First program: “Hello World” Open a terminal Make a perl dir(directory) in your home dir Move into the perl directory Create a file named ‘hello_world.pl’ Open the file in your text editor Code the program Save the file Make the program executable Test the program.

Perl script #!/usr/bin/perl -w use strict; my $name = ‘yupu’; print “\n hello world from $name.\n”;

Perl Data Types Scalar: a single piece of information. Scalars can hold numbers or text $ is the identifier of scalar in perl There are special variables for the system: $ARGV,$! List: an ordered collection of = ( 1, 2 = ( "first", "second", "third" ) Hash: special arrays with words as index.

Scalars $num = 42 $num2 = “42” $name = ‘joe’ $color = “blue” $string_w_num = “I have 10 apples” $foo = undef $foo = “” $foo =‘’

Scalar Functions: length reverse index

Quoting: double quotes(“), single quotes(‘) and multi- line quoting(qq) : $var =10; $text = “There are $var apples” $text2 = ‘There are $var apples’ $text3 = qq{ There are $var apples};

Functions/Subtroutines Functions are blocks of code which perform specific task #takes no input and returns no output… common practice to use #‘main’ as the starting point in a script. sub main { … } #Takes 2 *scalars* as input sums them and returns one scalar. sub sum_2_numbers { my ($numA,$numB) #get passed in values my $sum = $numA+$numB; #sum numbers return($sum); #return sum }

Control Structures: conditional statements if/else If statements are conditional statements used to test whether or not some condition is met and then continue executing the script. The syntax for an if statement has a specific flow to it - if(conditional_statment) { code to execute; } Logical operators: ==, !=, &&, ||, eq and ne unless

Boolean Undefined values are treated as false Scalars are evaluated as: numbers are evaluated as true if non-zero strings are evaluated as true if non-empty $var = “false”; if($var) { print “$var is true!\n”; }

Handling user inputs Scripts can take inputs in two ways: Arguments./print_args.pl ARG1 ARG2 Prompted inputs from users $user_text =

Error/Exception Handling Things don’t always come out as expected. It is good to check the output of important functions for errors, it is highly recommended to validate any input from users or external sources Die Warn

Write some scripts!