1 Introduction to Perl CIS*2450 Advanced Programming Techniques.

Slides:



Advertisements
Similar presentations
A Guide to Unix Using Linux Fourth Edition
Advertisements

Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
The Web Warrior Guide to Web Design Technologies
Second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Master Manipulator perl Perl is.
IT151: Introduction to Programming
Bioinformatics is … - the use of computers and information technology to assist biological studies - a multi-dimensional and multi-lingual discipline Chapters.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
CS311 – Today's class Perl – Practical Extraction Report Language. Assignment 2 discussion Lecture 071CS Operating Systems I.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Introduction to PHP. PHP Origins Rasmus LerdorfRasmus Lerdorf (born Greenland, ed Canada) PHP originally abbreviation for ‘Personal Home Pages’, now ‘PHP.
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.
Perl Basics A Perl Tutorial NLP Course What is Perl?  Practical Extraction and Report Language  Interpreted Language Optimized for String Manipulation.
Java An introduction. Example 1 public class Example1 { public static void main (String [] args) { System.out.println (“This is the first example”); int.
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.
Guide To UNIX Using Linux Third Edition
JavaScript, Third Edition
Basic Elements of C++ Chapter 2.
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 …
An Introduction to Unix Shell Scripting
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
1 System Administration Introduction to Scripting, Perl Session 3 – Sat 10 Nov 2007 References:  chapter 1, The Unix Programming Environment, Kernighan.
COMP519: Web Programming Autumn 2010 Perl Tutorial: The very beginning  A basic Perl Program The first line Comments and statements Simple printing 
Awk Dr. Tran, Van Hoai Faculty of Computer Science and Engineering HCMC Uni. of Technology
Chapter 9: Perl Programming Practical Extraction and Report Language Some materials are taken from Sams Teach Yourself Perl 5 in 21 Days, Second Edition.
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
Dr. Qusai Abuein1 Internet & WWW How to program Chap.(6) JavaScript:Introduction to Scripting.
_______________________________________________________________________________________________________________ PHP Bible, 2 nd Edition1  Wiley and the.
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
Introduction to Perl “Practical Extraction and Report Language” “Pathologically Eclectic Rubbish Lister”
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
 Creating and manipulating text has long been one of the primary tasks of scripting languages and  traditional shells. In fact, Perl (the language)
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Introduction to Perl October 4, 2004 Class Meeting 7 * Notes on Perl by Lenwood Heath, Virginia Tech © 2004.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Scripting with Ruby What is a scripting language? What is Ruby?
Basic Variables & Operators Web Programming1. Review: Perl Basics Syntax ► Comments: start with # (ignored by Perl) ► Statements: ends with ; (performed.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
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.
Session 2: PHP Language Basics iNET Academy Open Source Web Development.
Python 1 SIGCS 1 Intro to Python March 7, 2012 Presented by Pamela A Moore & Zenia C Bahorski 1.
Shell Scripting September 27, 2004 Class Meeting 6, Part II * Notes adapted by Lenwood Heath from previous work by other members of the CS faculty at Virginia.
REEM ALMOTIRI Information Technology Department Majmaah University.
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
Perl & TCL Vijay Subramanian, Modified from : perl_basics_06.ppt.
Web Database Programming Using PHP
Introduction to Perl: Practical extraction and report language
Chapter Topics The Basics of a C++ Program Data Types
Chapter 6 JavaScript: Introduction to Scripting
Web Database Programming Using PHP
Pamela Moore & Zenia Bahorski
Programming Basics Web Programming.
Basic Elements of C++.
Variables, Expressions, and IO
Introduction to Scripting
PHP Introduction.
Basic Elements of C++ Chapter 2.
Introduction to C++ Programming
PHP.
T. Jumana Abu Shmais – AOU - Riyadh
Tutorial 6 PHP & MySQL Li Xu
Introduction to Perl Learning Objectives:
Basic shell scripting CS 2204 Class meeting 7
Presentation transcript:

1 Introduction to Perl CIS*2450 Advanced Programming Techniques

2 What is Perl? Perl was developed by Larry Wall. –started out as a scripting language to supplement rn, the USENET reader. –available on virtually every computer platform Perl is an interpreted language that is optimized for string manipulation, I/O, and system tasks –has builtins for most of the functions in section 2 of the UNIX manuals -- very popular with sys administrators –incorporates syntax elements from the Bourne shell, csh, awk, sed, grep, and C –provides a quick and effective way to write interactive web applications

3 Basic Syntax Perl is free form. All Perl statements end in a semicolon, like C. Comments –begin with # –everything after the #, and up to the end of the line is ignored –the # needn't be at the beginning of the line #!/usr/bin/perl # # ereader - a simple Perl program to re-format

4 Variables Perl has several kinds of variables, or data structures. –Languages such as C and C++ have data types which are considered to be strongly typed, which means you must explicitly declare variables before you use them. –Languages such as Lisp or Smalltalk have data types that are determined dynamically, and if a variable holds a number, the programmer is responsible for making sure that the program doesn't try to pull substrings out of it. –Perl falls in the middle. Which data type you use is explicit in how you access it, but you don't need to declare it before you use it.

5 Perl Functions Perl has many built-in functions. Perl functions are identified by their unique names (print, chop, close, etc). The function's arguments are supplied as a comma separated list in parentheses. The commas are necessary, the parentheses are often not. print("length: ",length("hello world"));

6 Perl Functions: Example $date = `date`; chop($date); The first line executes the UNIX command date and puts the output in the the variable $date. Since the date has a newline in it, we want to chop that off.

7 Scalars Scalar Definition A scalar is a single value, either numeric or a character string. Scalars are accessed by prefixing an identifier with $. Identifier Definition An identifier is a variable name. –It is composed of upper or lower case letters, numbers, and the underscore _. –Identifiers are case sensitive (like all of Perl). Scalars are assigned by using = $scalar = expression;

8 Scalar Example $progname = "mailform"; This is read as the scalar progname is assigned the string mailform. The $ determines that progname is a scalar. The = determines that this an assignment. The double quotes (") define the string. All statements end with a semi-colon ;.

9 Strings There are several ways of quoting strings in Perl, corresponding to the three quote characters on the keyboard. " (double quote) interpolates (substitutes, expands) variables between the pair of quotes. $instr = "saxophone"; $little = "soprano $instr"; # the value of $little is “soprano saxophone”

10 ' (apostrophe) The simplest quote, text placed between a pair of apostrophes is interpreted literally - no variable interpolation takes place. $instr = 'saxophone'; $little = 'soprano $instr'; # the value of $little includes the text “$instr” –To include an apostrophe in the string, you must escape it with a backslash: "sax\'s"

11 ` (backtick) This quote performs as it does in the UNIX shells –the text inside the backticks is executed as a separate process, and the standard output of the command is returned as the value of the string. –Backticks perform variable interpolation, and to include a backtick in the string, you must escape it with a backslash. $memberList = "/usr/people/conductor/roster"; $memberCount = `wc -l $memberList`; # $memberCount is the no. of members in the roster file, # assuming that each member is listed on a separate line.

12 Example # the sendmail binary. $sendmail = "/usr/lib/sendmail"; # base of your httpd installation. $basedir = '/www'; # log file $progname = "apache"; $logfile = "$basedir/etc/logs/$progname.log"; # today $date = `date`; /www/etc/logs/apache.log