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.

Slides:



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

Adv. UNIX:Perl/81 Advanced UNIX v Objectives of these slides: –introduce Perl (version ) –mostly based on Chapter 1, Learning Perl
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.
Introduction to Perl Bioinformatics. What is Perl? Practical Extraction and Report Language A scripting language Components an interpreter scripts: text.
CSET4100 – Fall 2009 Perl Introduction Scalar Data, Operators & Control Blocks Acknowledgements: Slides adapted from NYU Computer Science course on UNIX.
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
Scalar Variables Start the file with: #! /usr/bin/perl –w No spaces or newlines before the the #! “#!” is sometimes called a “shebang”. It is a signal.
Integer variables #!/bin/csh # sum of numbers from $argv[1] to $argv[2] set low = $argv[1] set high = $argv[2] set sum = 0 set current = $low while ( $current.
Perl Basics A Perl Tutorial NLP Course What is Perl?  Practical Extraction and Report Language  Interpreted Language Optimized for String Manipulation.
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.
Perl Lecture #1 Scripting Languages Fall Perl Practical Extraction and Report Language -created by Larry Wall -- mid – 1980’s –needed a quick language.
Operators. Perl has MANY operators. –Covered in Chapter 3 of Prog.Perl Most operators have numeric and string version –remember Perl will convert variable.
Introduction to Perl Software Tools. Slide 2 Introduction to Perl l Perl is a scripting language that makes manipulation of text, files, and processes.
CS 898N – Advanced World Wide Web Technologies Lecture 7: PERL Chin-Chih Chang
5.1 Revision: Ifs and Loops. 5.2 if, elsif, else It’s convenient to test several conditions in one if structure: print "Please enter your grades average:\n";
3ex.1 Note: use strict on the first line Because of a bug in the Perl Express debugger you have to put “use strict;” on the first line of your scripts.
Shell Programming 1. Understanding Unix shell programming language: A. It has features of high-level languages. B. Convenient to do the programming. C.
Practical Extraction & Report Language PERL Joseph Beltran.
1 Perl Perl basics Perl Elements Arrays and Hashes Control statements Operators OOP in Perl.
Introduction to programming in Perl. What is Perl ? Perl : Practical Extraction and Report Language by Larry Wall in 1987 Text-processing language Glue.
ECMM6018 Enterprise Networking For Electronic Commerce Tutorial 5 Server Side Scripting Perl.
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.
CSC 352– Unix Programming, Spring 2015 March 2015 Shell Programming (Highlights only)
Shell Script & Perl Programming Lesson 9. Shell Programming A shell script is a text file that contains Linux (UNIX) commands, which you enter using any.
Perl Practical(?)‏ Extraction and Report Language.
Bioinformatics 生物信息学理论和实践 唐继军
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.
Programming Languages Meeting 14 December 9/10, 2014.
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
1 Introduction to Perl CIS*2450 Advanced Programming Techniques.
Introduction to Perl “Practical Extraction and Report Language” “Pathologically Eclectic Rubbish Lister”
A Stroll through Perl (R L Schwartz & T Christiansen, O’Reilly) PERL = Practical Extraction and Report Language. A major strength of Perl is the recognition.
Introducing System Managers to Win32 Perl Programming Tim Christian College of Arts and Sciences Computing Support Services.
CPTG286K Programming - Perl Chapter 4: Control Structures.
Introduction to Perl October 4, 2004 Class Meeting 7 * Notes on Perl by Lenwood Heath, Virginia Tech © 2004.
CPTG286K Programming - Perl Chapter 1: A Stroll Through Perl Instructor: Denny Lin.
Topic 2: Working with scalars CSE2395/CSE3395 Perl Programming Learning Perl 3rd edition chapter 2, pages 19-38, Programming Perl 3rd edition chapter.
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 Lab #11 Intro to Perl Debbie Bartlett. Perl Lab #1 2 Perl Practical Extraction and Report Language –or- Pathologically Eclectic Rubbish Lister Created.
Computer Programming for Biologists Class 4 Nov 14 th, 2014 Karsten Hokamp
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.
File Handle and conditional Lecture 2. File Handling The Files associated with Perl are often text files: e.g. text1.txt Files need to be “opened for.
PZ02CX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ02CX - Perl Programming Language Design and Implementation.
Operators. Perl has MANY operators. –Covered in Chapter 3 of Camel –perldoc perlop Many operators have numeric and string version –remember Perl will.
1 Lecture 8 Shell Programming – Control Constructs COP 3353 Introduction to UNIX.
Perl & TCL Vijay Subramanian, Modified from : perl_basics_06.ppt.
Organization of Programming Languages Meeting 37 April 18, 2016.
The full name of PERL is Practical extraction and report language. It is similar to shell script and lot easier & powerful language. Perl is free to download.
Perl Programming Language Design and Implementation (4th Edition)
An Introduction to Perl – Part I
Control Structures: if Conditional
An Introduction to Perl
Control Structures: for & while Loops
Lesson 2. Control structures File IO - reading and writing Subroutines
Programming Perls* Objective: To introduce students to the perl language. Perl is a language for getting your job done. Making Easy Things Easy & Hard.
Programming Languages
The Selection Structure
CSC 352– Unix Programming, Fall 2012
Introduction to Bash Programming, part 3
INTRODUCTION to PERL PART 1.
Karan Thaker CS 265 Section 001
Presentation transcript:

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 languages See

Perl by Example Perl is more powerful than awk, but looks somewhat the same. Perl is more flexible than shell scripts, but uses some of the same constructs. Perl is based on C, and in fact the interpreter is written in C, but is easier to use than C.

Perl by Example (2) Beginning assumptions and notations Statements are terminated by ; (semicolon) Comments start anywhere on a line with # and end at the end of the line. Thus, you can write explanations on the line for the line. But they can’t be two line explanations. Built-in functions neither require nor forbid ( ) around their arguments

Perl by Example (3) First line of Perl program should be a directive to the interpreter; e.g. (either) #! /opt/local/bin/perl –w #! /usr/bin/perl –w Invoke by perl or Scalar variables have names that start with $ and have values that are either strings or double precision real numbers.

Exercise 1 #! /opt/local/bin/perl –w print (“Hello, world!\n”);

Exercise 2 #! /opt/local/bin/perl –w print “What is your name? “; $name = ; chomp ($name); print “Hello, $name!\n”;

Exercise 3 #!/opt/local/bin/perl –w print “What is your name? “; $name = ; chomp ($name); if ($name eq “Randal”) { print “Hello, $name! Glad you’re here\n” } else { print “Hello, $name!\n”; # ordinary greeting }

Exercise 4 #! /opt/local/bin/perl –w $secretword = “llama”; # the secret word print “What is your name? ”; chomp($name = ); if ($name eq “Randal”) { print “Hello, $name! Glad you’re here\n” } else { print “Hello, $name!\n”; print “What is the secret word? ”; chomp($guess = ); while ($guess ne $secretword) { print “Wrong, try again. Secret word? ”; chomp($guess = ); }

Non-scalar Variables For example, arrays: –Identifier starts with –Can be initialized with a list of = (“camel”, “llama”, “alpaca”); –Or with the qw operator (which saves = qw (camel llama alpaca); –Elements accessed as scalars, so $words[0] is camel, $words[1] is llama NB: Index origin is 0 –$i = 2 ; $words[$i] has value alpaca

Exercise 5 #!/opt/local/bin/perl = qw (camel llama alpaca); #set multiple secret words print “What is your name? ”; chomp($name = ); if ($name eq “Randal”) { print “Hello, $name! Glad you’re here\n” } else { print “Hello, $name!\n”; print “What is the secret word? ”; chomp($guess = ); $i = 0; #index in swords array $correct = “maybe”; #status of search while ($correct eq “maybe”) { if($guess eq $swords[$i]) { $correct = “yes”} # set flag on success elsif ($i < 2) {++$i} # not success, try next secret word else { print “Wrong, try again. Secret word? ”; # no word matches, ask again chomp($guess = ); $i=0; # reset index in secret word array } # end if sequence } # end while not correct } # end if not Randal

Scalar operators Numeric: + - * / ** % Numeric comparison: = > != String:. (for concat) x (for multiple concat) String comparison: lt le eq ge gt ne Identifier: $ … Assignment: = (carries value of expression) binary assignment: += *=.= etc. increment: prefix, postfix ++$i $i++ increment then assign vs. assign then increment