Introduction to Perl “Practical Extraction and Report Language” “Pathologically Eclectic Rubbish Lister”

Slides:



Advertisements
Similar presentations
Arrays A list is an ordered collection of scalars. An array is a variable that holds a list. Arrays have a minimum size of 0 and a very large maximum size.
Advertisements

Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
CSC 4630 Perl 1. Perl Practical Extraction and Support Language A glue language under UNIX Written by Larry Wall Claimed to be the most portable of scripting.
Second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Master Manipulator perl Perl is.
C Introduction Lesson CS1313 Spring C Introduction Lesson Outline 1.C Introduction Lesson Outline 2. hello_world.c 3.C Character Set 4.C is Case.
C Introduction Lesson CS1313 Spring C Introduction Lesson Outline 1.C Introduction Lesson Outline 2. hello_world.c 3.C Character Set 4.C is Case.
Introduction to C Programming
Input from STDIN STDIN, standard input, comes from the keyboard. STDIN can also be used with file re-direction from the command line. For instance, if.
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
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.
Introduction to Perl Learning Objectives: 1. To introduce the features provided by Perl 2. To learn the basic Syntax & simple Input/Output control in Perl.
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
Introduction to Perl. How to run perl Perl is an interpreted language. This means you run it through an interpreter, not a compiler. Your program/script.
CSC3530 Software Technology Tutorial Two PERL Basics.
PHYS 2020 Making Choices; Arrays. Arrays  An array is very much like a matrix.  In the C language, an array is a collection of variables, all of the.
1ex.1 Perl Programming for Biology Exercise 1 The Bioinformatics Unit G.S. Wise Faculty of Life Science Tel Aviv University, Israel March 2009 Eyal Privman.
Perl Lecture #1 Scripting Languages Fall Perl Practical Extraction and Report Language -created by Larry Wall -- mid – 1980’s –needed a quick language.
Introduction to Perl Software Tools. Slide 2 Introduction to Perl l Perl is a scripting language that makes manipulation of text, files, and processes.
Perl File I/O and Arrays. File I/O Perl allows to open a file to read, write, or append As well as pipe input or output to another program. —We get to.
Guide To UNIX Using Linux Third Edition
Guide To UNIX Using Linux Third Edition
Introduction to C Programming
Perl - Advanced More Advanced Perl  Functions  Control Structures  Filehandles  Process Management.
Introduction to Array The fundamental unit of data in any MATLAB program is the array. 1. An array is a collection of data values organized into rows and.
Java Unit 9: Arrays Declaring and Processing Arrays.
Computer Programming for Biologists Class 2 Oct 31 st, 2014 Karsten Hokamp
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:
Perl Tutorial Presented by Pradeepsunder. Why PERL ???  Practical extraction and report language  Similar to shell script but lot easier and more powerful.
C++ Basics Structure of a Program. C++ Source Code Plain text file Typical file extension .CPP Must compile the C++ source code without errors before.
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.
Meet Perl, Part 2 Flow of Control and I/O. Perl Statements Lots of different ways to write similar statements –Can make your code look more like natural.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
Introduction to Perl Yupu Liang cbio at MSKCC
Chapter 9: Perl Programming Practical Extraction and Report Language Some materials are taken from Sams Teach Yourself Perl 5 in 21 Days, Second Edition.
Introduction to Unix – CS 21
Prof. Alfred J Bird, Ph.D., NBCT Office – McCormick 3rd floor 607 Office Hours – Tuesday and.
1 Introduction to Perl CIS*2450 Advanced Programming Techniques.
5 1 Data Files CGI/Perl Programming By Diane Zak.
A first program 1. #include 2. using namespace std; 3. int main() { 4. cout
Perl Tutorial. Why PERL ??? Practical extraction and report language Similar to shell script but lot easier and more powerful Easy availablity All details.
Fall 2002CS 150: Intro. to Computing1 Streams and File I/O (That is, Input/Output) OR How you read data from files and write data to files.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
Topic 4:Subroutines CSE2395/CSE3395 Perl Programming Learning Perl 3rd edition chapter 4, pages 56-72, Programming Perl 3rd edition pages 80-83,
Scripting Languages Diana Trandab ă ț Master in Computational Linguistics - 1 st year
Introduction to Perl NICOLE VECERE. Background General Purpose Language ◦ Procedural, Functional, and Object-oriented Developed for text manipulation.
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 Variables: Array Web Programming1. Review: Perl Variables Scalar ► e.g. $var1 = “Mary”; $var2= 1; ► holds number, character, string Array ► e.g.
Perl Lab #11 Intro to Perl Debbie Bartlett. Perl Lab #1 2 Perl Practical Extraction and Report Language –or- Pathologically Eclectic Rubbish Lister Created.
General Computer Science for Engineers CISC 106 Lecture 12 James Atlas Computer and Information Sciences 08/03/2009.
Chapter 8 Arrays. A First Book of ANSI C, Fourth Edition2 Introduction Atomic variable: variable whose value cannot be further subdivided into a built-in.
2.1 Scalar data - revision numeric e-14 ( = 6.35 × )‏ operators: + (addition) - (subtraction) * (multiplication) / (division)
Introduction to Perl Practical Extraction and Report Language or Pathologically Eclectic Rubbish Lister or …
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
Perl for Bioinformatics Part 2 Stuart Brown NYU School of Medicine.
Dept. of Animal Breeding and Genetics Programming basics & introduction to PERL Mats Pettersson.
Perl Subroutines User Input Perl on linux Forks and Pipes.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Linux Administration Working with the BASH Shell.
Built-In Functions. Notations For each function, I will give its name and prototype. –prototype = number and type of arguments ARRAY means an actual named.
2.1 First C Program. First Program Open visual studio, click new file Save as “programName.c” – Program must start with letter and have no spaces – Must.
Organization of Programming Languages Meeting 37 April 18, 2016.
Last week: We talked about: History of C Compiler for C programming
Miscellaneous Items Loop control, block labels, unless/until, backwards syntax for “if” statements, split, join, substring, length, logical operators,
Strings, Line-by-line I/O, Functions, Call-by-Reference, Call-by-Value
Perl Variables: Array Web Programming.
T. Jumana Abu Shmais – AOU - Riyadh
Introduction to Perl Learning Objectives:
LING/C SC/PSYC 438/538 Lecture 4 Sandiway Fong.
Presentation transcript:

Introduction to Perl “Practical Extraction and Report Language” “Pathologically Eclectic Rubbish Lister”

How to run Perl Perl is an interpreted language. This means you run it through an interpreter, not a compiler. 2 methods: –Run interpreter directly, giving name of perlscript as argument /afs/rpi.edu/home/36/lallip (1) perl myfile.pl –Run as a Unix shell program. First line of program will tell the shell where the Perl interpreter is located –This line is called the “shebang” –#!/usr/local/bin/perl mildly different from the book must be VERY first line – no comments, blank lines preceding

One more step… If you choose to use the shebang, you must tell the OS that this is an executable file. Use chmod (see intro to unix slides) Usually only need to give yourself execute permissions. Once it’s executable, type the filename at a prompt, and it runs. This is the preferred method of running Perl

Perl Script Structure semicolon ends each simple statement semicolon optional at final line of a block or loop –optional, but very recommended Comments begin with # and extend to end of line –don’t try to use // or /* … */ variables do not need to be declared –unless you put use strict; at beginning of script this also is recommended, but not necessary. Perl will try to figure out what you mean –won’t even give warnings, unless you tell it to –either use warnings; or put –w after shebang or command line –this is VERY Recommended. Homeworks will lose points if they produce warnings.

Very basic I/O simple introduction to reading/writing from keyboard/terminal. More advanced (ie, File) I/O will come around in a couple weeks. This will be just enough to allow us to do some examples, if necessary.

Output to terminal the print statement. Takes 0 or more arguments. First (optional) argument is the filehandle. –if omitted, prints to STDOUT. Second, third, fourth, etc… arguments are what to print. –if omitted, prints what ever is in variable $_

Output examples Hello World program: #!/usr/bin/local/perl print “Hello World\n”; as this is perl, you can put string in paren’s, but you don’t need to (usually – because this is Perl). more examples: –print “My name is $name\n”; –print “Hi ”, “what\’s ”, “yours?\n”; –print 5 + 3; –print ((4 * 4). “\n”);

Input from keyboard read line operator: <> –aka “angle operator”, “diamond operator” –Encloses file handle to read from. Defaults to STDIN, which is what we want. $input = <>; –read one line from STDIN, and save in $input (See variable section, later in this = <>; –read all lines from STDIN, and save as array Again, this makes more sense later on…

Our First Bit of Magic The Camel will describe several Perl features as “magical”. The <> operator is the first such feature. If you pass the name of a file (or files) as command line arguments to your script, <> does not read from STDIN. Instead, it will automatically open the first file on the command line, and read from that file. When first file exhausted, it opens and reads from next file. When all files exhausted, THEN <> reads from STDIN

Chop & Chomp When reading in a line, carriage return (“\n”) is included. Usually don’t want that. chomp will take off the last character of a string, if it is a “\n”. chop takes off last character of a string, regardless of what it is. –Hence, chomp is “safer”. chomp ($foo = <>); –Very common method of reading in one string from input.

Variables Three (basic) types of variables. –Scalar –Array –Hash There are others, but we’ll talk about them at a later time….

Scalars Scalar = “single value” In C/C++, many many different kinds of single values: –int, float, double, char, bool In Perl, none of these types need to be declared Scalar variable can hold all these types, and more.

Scalars All Scalar variables begin with a $ next character is a letter or _ remaining characters: letters, numbers, or _ Variable names can be between 1 and 251 characters in length Ex: $foo, $a, $zebra1, $F87dr_df3 Wrong: $24da, $hi&bye, $bar$foo

Scalar Assignments Scalars hold any data type: $foo = 3; $d = 4.43; $temp = ‘Z’; $My_String = “Hello, I’m Paul.”

Arrays Concept is the same as in C/C++ –Groups of other values –Groups of scalars, arrays, hashes much more dynamic than C/C++ –no declaration of size, type –can hold any kinds of value, and multiple kinds of values All array variables start with

Array = (1, 2, 3, = (“hello”, “my”, “name”, “is”, = (34, ‘z’, “Hi!”, 43.12); Arrays are 0-indexed, just as in C/C++ $temp[1]  ‘z’; –NOTE: This is a *single value*, hence the $ $bar[3] = “was”; now: (“hello”, “my”, “name”, “was”, “Paul”);

Array vs. Scalar $foo = = (43.3, 10, 8, 5.12, “a”); $foo have *nothing in common*. In fact, $foo has nothing to do with $foo[3]; “This may seem a bit weird, but that’s okay, because it is weird.” –Programming Perl, pg. 54

More about arrays special variable for each array: = (3, 25, 43, 31); –$#foo  3. Last index –$foo[$#foo]  31; This can be used to dynamically alter the size of an array: –$#foo = 5; -- creates two null values on the end –$#foo = 2; -- destroys all but the first three elements “Slices” – part of an array (or  (25, 43,  (3, 25)

Join/Split Built-in Perl functions Split – split a string into a list of values –$BigString = “Hello,_I_am_Paul”; = split ‘_’, $BigString;  (“Hello,”, “I”, “am”, “Paul”); Join – join a list/array of values together –$BigString = join ‘ –$BigString  “Hello, I am Paul”;

Hash (somewhat) Analogous to C++ hashtable. aka “Associative Array” – ie, array not indexed by numerical sequence. list of keys and values. All hash variables start with % Use to keep list of corresponding values –TIP: Any time you feel the need to have two separate arrays, and do something with elements at corresponding positions in the arrays (but don’t care where in array elements actually are), USE A HASH

Hash example Want a list of short names for months: %months = ( “Jan” => “January”, “Feb” => “February”, “Mar” => “March”, … ); reference by *curly* brackets… –Avoid confusion with array notation $month{“Jan”}  “January”;