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.

Slides:



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

1/12 Steven Leung Very Basic Perl Tricks A Few Ground Rules File I/O and Formatting Operators, Flow Control Statements Regular Expression Subroutines Hash.
Shell Scripting Printing; Loops and Logic printf: formatted print printf is a more standardized method to print text to the screen. It can be used instead.
A Guide to Unix Using Linux Fourth Edition
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.
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 Unix – CS 21 Lecture 11. Lecture Overview Shell Programming Variable Discussion Command line parameters Arithmetic Discussion Control.
CSET4100 – Fall 2009 Perl Introduction Scalar Data, Operators & Control Blocks Acknowledgements: Slides adapted from NYU Computer Science course on UNIX.
CS 898N – Advanced World Wide Web Technologies Lecture 8: PERL Chin-Chih Chang
CS311 – Today's class Perl – Practical Extraction Report Language. Assignment 2 discussion Lecture 071CS Operating Systems I.
CS 497C – Introduction to UNIX Lecture 33: - Shell Programming Chin-Chih Chang
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.
Practical Extraction & Report Language Picture taken from
Bash, part 2 Prof. Chris GauthierDickey COMP Unix Tools.
Operators. Perl has MANY operators. –Covered in Chapter 3 of Prog.Perl Most operators have numeric and string version –remember Perl will convert variable.
CS 898N – Advanced World Wide Web Technologies Lecture 7: PERL Chin-Chih Chang
Bash Shell Scripting 10 Second Guide Common environment variables PATH - Sets the search path for any executable command. Similar to the PATH variable.
Shell Scripting Awk (part1) Awk Programming Language standard unix language that is geared for text processing and creating formatted reports but it.
Practical Extraction & Report Language PERL Joseph Beltran.
1 Perl Perl basics Perl Elements Arrays and Hashes Control statements Operators OOP in Perl.
Introduction To Perl Susan Lukose. Introduction to Perl Practical Extraction and Report Language Easy to learn and use.
Lecture 10A Perl: Programming Freedom Fundamentals of Engineering For Honors – H192 By Robert Mohr, Ted Pavlic, and Joe Ryan.
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.
A very basic overview of Server-Side Scripting Or what is PHP, Perl, Python, Ruby and what can they do for me?
Perl Practical(?)‏ Extraction and Report Language.
Week Four Agenda Announcements Link of the week Review week three lab assignment This week’s expected outcomes Next lab assignment Break-out problems.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
Introduction to Perl Yupu Liang cbio at MSKCC
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.
Chapter 10: BASH Shell Scripting Fun with fi. In this chapter … Control structures File descriptors Variables.
Prof. Alfred J Bird, Ph.D., NBCT Office – McCormick 3rd floor 607 Office Hours – Tuesday and.
C++ Lecture 1 Friday, 4 July History of C++ l Built on top of C l C was developed in early 70s from B and BCPL l Object oriented programming paradigm.
(A Very Short) Introduction to Shell Scripts CSCI N321 – System and Network Administration Copyright © 2000, 2003 by Scott Orr and the Trustees of Indiana.
Introduction to Perl William G. Dishman CUR/516 November 5, 2014.
Introducing System Managers to Win32 Perl Programming Tim Christian College of Arts and Sciences Computing Support Services.
©Colin Jamison 2004 Shell scripting in Linux Colin Jamison.
Chapter 11: Perl Scripting Off Larry’s Wall. In this chapter … Background Terminology Syntax Variables Control Structures File Manipulation Regular Expressions.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
CS 105 Perl: Basic I/O, Context, Strings, Lists Nathan Clement January 22, 2014.
Introduction to Perl October 4, 2004 Class Meeting 7 * Notes on Perl by Lenwood Heath, Virginia Tech © 2004.
More Perl Data Types Scalar: it may be a number, a character string, or a reference to another data type. -the sigil $ is used to denote a scalar(or reference)
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.
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.
Week Five Agenda Link of the week Review week four lab assignment This week’s expected outcomes Next lab assignment Break-out problems Upcoming deadlines.
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.
Scripting Languages ● Perl, Python, Unix Shell, VB, JavaScript, etc. ● Glue Languages. ● Typeless. ● Interchangeable Code and Data. ● Interpreted vs. Compiled.
PERL By C. Shing ITEC Dept Radford University. Objectives Understand the history Understand constants and variables Understand operators Understand control.
The Scripting Programming Language
Perl References arrays and hashes can only contain scalars (numbers and strings)‏ if we want something more complicated (like an array of arrays) we use.
Operators. Perl has MANY operators. –Covered in Chapter 3 of Camel –perldoc perlop Many operators have numeric and string version –remember Perl will.
Perl Ed Finegan. Overview of Pearl Perl is a high-level programming language written by Larry Wall. It derives from the C programming language and to.
Week Four Agenda Announcements Link of the week Review week three lab assignment This week’s expected outcomes Next lab assignment Break-out problems.
1 Lecture 8 Shell Programming – Control Constructs COP 3353 Introduction to UNIX.
Organization of Programming Languages Meeting 37 April 18, 2016.
Introduction to Python
Control Structures: if Conditional
An Introduction to Perl
Control Structures: for & while Loops
Pemrosesan Teks Herika Hayurani Sept 19, 2006
Lesson 2. Control structures File IO - reading and writing Subroutines
The Selection Structure
Introduction to Bash Programming, part 3
INTRODUCTION to PERL PART 1.
Karan Thaker CS 265 Section 001
Presentation transcript:

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 a general purpose programming language -System administration -Web development -Network programming -GUI development, and more.

Features Perl takes many good features from other languages. The overall structure of Perl is from C. - Variables, expressions, assign statements, control structures and subroutines. Perl also adopts features from shell scripting languages. - Every variable has a leading sigils, - Lists, hashes and regular expressions

Features (cont.) Perl has many built-in functions that cover very large range of operations. Perl not only supports procedural programming and also supports object- oriented programming. Perl is widely used for web programming Perl works on multiple platforms

Perl Syntax Basic Script #!/usr/bin/perl $inputline = ; print($inputline); Data Types Perl has three main variable types: -scalars, arrays, and hashes -dynamically typed.

Scalars A scalar represents a single value: -string, integer or floating point numbers. -automatic conversion. $string = "hello"; $color = ‘green’; $num = 88; $float = 9.58;

= (“cat", “dog", = (11, 22, = ("cat", 1.23);

Hashes A hash is a set of key/value pairs: - %ages = ("li"=>18,“jin"=>21); - %same = ("li",18,“jin",21); - %mixed = (1=>“Mon", “flow"=>2.1) - %empty_hash = ();

Complex data types Reference: A scalar value $scalarref = \$num; $arrayref = $hashref = \%ages;

Complex data types - A reference can refer to any other Perl data type: $table = { “jin” => { age => 47; id => “teacher”, }, “mei” => { age => 21 id => “student”, }, “tom” => { age => 59 id=> “retired”, }, };

Operators Arithmetic Boolean logic + addition && and - subtraction || or * multiplication! not / division ** exponential

Comparison Numeric /String == /eq equal != /ne not equal < / lt less than > / gt greater than <= / le less than or equal >= / ge greater than or equal

Pattern Matching. any character except newline \s white space (space, tab, newline...) \S non-white space \d any digit (0-9) \D any non-digit \w any word character (a-z, A-Z, 0-9, _) \W any non-word character [abcde] any single character within the set [^abcde] any single character outside the set | alternatives ^ beginning of string $ end of string * + ? { } number of occurrences () pattern memory

Conditional constructs if (cond ) {... } if (cond ) {... } else {... } if (cond ) {... } elsif (cond ) {... } else {... } Negated if statement: unless cond {…} post-condition {…} if (cond)

Looping constructs while (cond ) {... } while (cond ) {... } continue {... } Negated while statement until (cond ) {…} post-condition of while {…} while (cond);

Looping constructs for ( init-expr ; cond-expr ; incr-expr ) {... } foreach var ( list ) {... } foreach var ( list ) {... } continue {... } {…} foreach var (list) a multi-way branch statement - given ( expr ) { when ( cond ) {... } default {... } }

Subroutines Call subroutine - subname(); -&subname; - $cub = cubic(8); Example: sub cubic { my $num = shift; my $result = $num * $num * $num; return $result; } pass-by-value, pass-by-reference

Ruby vs. Perl Perl is good for simple procedural scripts Ruby is object-oriented programming. Every data type in Ruby is an object, which makes Ruby OOP syntax much simpler than Perl. Ruby is easier to maintain and read than Perl. Ruby is less documentation, less modules and fewer available libraries.

Evaluation (writability) Perl is easy to write, specially for little utilities - Very flexible syntax. -Provides many functionalities -“Perl makes easy things easy and hard things possible”

Evaluation (flexibility) Perl is very flexible. There is always more than one way to implement the code. while (<>) { next if /^#/; # skip the comment line. print; } print grep !/^#/, <>; print `grep -v '^#'`;

Evaluation (readability & maintenance) Perl is very difficult to read sometimes, specially to understand other one’s code. $/ = “ ”; While(<>) { while (m { \b (\w\S+) ( \s+ \1 ) + \b } xig ) { print “dup word ‘$1’ at paragraph $. \n”; } This readability problem makes it difficult to maintain other programmer’s code.

Evaluation (reliability) The scalar type has both strings and numbers. There is no way to check array indexing References to nonexistent elements return undef

Evaluation (cost) Development time is shorter and less cost. -Perl is a scripting language and has many flexible features. This makes it easier to learn and faster to write. The Perl is free software.

Reference Programming Perl, O'Reilly Media,Programming PerlO'Reilly Media