Chapter 16 Introduction to Perl Perl (Practical Extraction and Report Language) Developed by Larry Wall as a Unix scripting language. Popular server-side.

Slides:



Advertisements
Similar presentations
Chapter 25 Perl and CGI (Common Gateway Interface)
Advertisements

Scalar Data Types and Basic I/O
A Guide to Unix Using Linux Fourth Edition
Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
Second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX – The Master Manipulator perl Perl is.
Chapter 4: Introduction to Perl and CGI programming. PERL -- Practical Extraction and Report Language Developed in 1980's by Larry Wall He created it to.
Computer Science A 2: 6/2. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated.
JavaScript, Fourth Edition
ASP.NET Programming with C# and SQL Server First Edition
JavaScript, Third Edition
PHP Server-side Programming. PHP  PHP stands for PHP: Hypertext Preprocessor  PHP is interpreted  PHP code is embedded into HTML code  interpreter.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 25 – Perl and CGI (Common Gateway Interface) Outline 25.1 Introduction 25.2 Perl 25.3 String Processing.
PHP Overview CS PHP PHP = PHP: Hypertext Preprocessor Server-side scripting language that may be embedded into HTML One goal is to get PHP files.
Python Programming Fundamentals
EG280 - CS for Engineers Chapter 2, Introduction to C Part I Topics: Program structure Constants and variables Assignment Statements Standard input and.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
Computer Programming Fundamental Data Types Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons.
COP 3813 Intro to Internet Computing Prof. Roy Levow PHP.
1 An Introduction to Perl Part 1 CSC8304 – Computing Environments for Bioinformatics - Lecture 7.
Writing Web Pages By Shyam Gurram. Agenda Writing Web Pages Delimiting PHP Program Units. Displaying Output to Web Pages Putting Comments in PHP Programs.
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
2440: 211 Interactive Web Programming Expressions & Operators.
Chapter 3: Data Types and Operators JavaScript - Introductory.
Chapter 2 Basic Elements of Java. Chapter Objectives Become familiar with the basic components of a Java program, including methods, special symbols,
Constants in C A Presentation On Department of Computer & Information Technology, M.S.P.V.L. Polytechnic College, Pavoorchatram.
ENG 1181 College of Engineering Engineering Education Innovation Center MATLAB is a powerful program for numerical computations, plotting and programming.
Chapter 5 NUTS AND BOLTS: STANDARD STUFF IN C++. Chapter 5 The C++ Arithmetic Operators –Addition+ –Subtraction– –Multiplication  –Division/ –Modulus.
TUTORIAL 10: PROGRAMMING WITH JAVASCRIPT Session 2: What is JavaScript?
November 2003Bent Thomsen - FIT 6-11 IT – som værktøj Bent Thomsen Institut for Datalogi Aalborg Universitet.
Chapter 2: Using Data.
1 System Administration Introduction to Scripting, Perl Session 3 – Sat 10 Nov 2007 References:  chapter 1, The Unix Programming Environment, Kernighan.
Introduction to PHP A user navigates in her browser to a page that ends with a.php extension The request is sent to a web server, which directs the request.
STANDARD FUNCTIONS Computer Programming Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat.
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
COMP519: Web Programming Autumn 2010 Perl Tutorial: The very beginning  A basic Perl Program The first line Comments and statements Simple printing 
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. int: integers, no fractional part: 1, -4, 0 double : floating-point.
Introduction to PHP Advanced Database System Lab no.1.
Perl: Lecture 1 The language. What Perl is Merger of Unix tools – Very popular under UNIX – shell, sed, awk Programming language – C syntax Scripting.
13 More Advanced Awk Mauro Jaskelioff (originally by Gail Hopkins)
Visual Basic I Programming
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
1 Ordinal types An ordinal data type is an ordered set in which every element, except the first element, has an immediate predecessor, and every element,
Introduction to Perl October 4, 2004 Class Meeting 7 * Notes on Perl by Lenwood Heath, Virginia Tech © 2004.
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.
Basic Variables & Operators Web Programming1. Review: Perl Basics Syntax ► Comments: start with # (ignored by Perl) ► Statements: ends with ; (performed.
CST336, Dr. Krzysztof Pietroszek Week 2: PHP. 1.Introduction to PHP 2.Embed PHP code into an HTML web page 3.Generate (output HTML) web page using PHP.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP Basics.
Chapter 1 Introduction to PHP Part 1. Textbook’s Code DOWNLOADS PHP and MySQL for Dynamic Web Sites Complete Set of Scripts.
Chapter 14 JavaScript: Part II The Web Warrior Guide to Web Design Technologies.
1 PHP Intro PHP Introduction After this lecture, you should be able to: Know the fundamental concepts of Web Scripting Languages in general, PHP in particular.
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
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.
L131 Assignment Operators Topics Increment and Decrement Operators Assignment Operators Debugging Tips rand( ) math library functions Reading Sections.
PHP using MySQL Database for Web Development (part II)
Simple C Programs.
Today Variable declaration Mathematical Operators Input and Output Lab
CSC 4630 Meeting 7 February 7, 2007.
Chapter 6 JavaScript: Introduction to Scripting
CHAPTER 5 SERVER SIDE SCRIPTING
BIL 104E Introduction to Scientific and Engineering Computing
Introduction to PHP Part 1
TMF1414 Introduction to Programming
Introduction to Scripting
PHP Introduction.
Java Programming: From Problem Analysis to Program Design, 4e
Chapter 2: Basic Elements of Java
Chapter 2: Introduction to C++.
The <script> Tag
Lexical Elements & Operators
Presentation transcript:

Chapter 16 Introduction to Perl Perl (Practical Extraction and Report Language) Developed by Larry Wall as a Unix scripting language. Popular server-side web development language.

Chapter 16 The First Perl Page This page uses Perl to create HTML tags.

Chapter 16 The First Perl Page #!/usr/local/bin/perl # File name: hello.pl.cgi print "Content-type: text/html", "\n\n"; print " ", "\n"; print " Web Hello \n"; print " \n"; print "Hello, World Wide Web! \n"; print "This is SAF\n"; print " ", "\n"; exit(0); This code creates the first Perl page.

Chapter 16 Perl Basics Perl uses a pound, #, to denote a comment. The comment ends when the line ends. A web page must indicate the content type: print "Content-type: text/html", "\n\n"; Perl programs should end with: exit(0);

Chapter 16 Perl Quotation Marks Double quotations: “ “. Variables and escape sequence are interpolated. Single quotations: ‘’ Variables and escape sequence are NOT interpolated. Back quotations: `` Command execution mode. Here Document: Quotations are not needed.

Chapter 16 Double Quotation Marks #!/usr/local/bin/perl $Title = "My First Web Page"; $Name = "Susan"; $Background = "white";... print "Hello, World Wide Web! \n"; print "This is $Name!\n"; Double quotation marks indicate that variable and escape sequences should be interpolated.

Chapter 16 Single Quotation Marks #!/usr/local/bin/perl $Title = "My First Web Page"; $Name = "Susan"; $Background = "white";... print ‘Hello, World Wide Web! \n’; print ‘This is $Name!\n’; Single quotation marks indicate that variable and escape sequences are NOT interpolated.

Chapter 16 Back Quotation Marks Back quotation marks are used for command execution.

Chapter 16 Back Quotations print "Echo Command: ", `echo My name is Susan`, " \n"; print "Word count(hello.pl.cgi): ”, “Lines, Words, Characters: \n"; print `wc hello.pl.cgi`, "\n"; print " ", "\n"; exit(0); This code executes Unix commands.

Chapter 16 Perl Scalar Variables Perl uses a $ to denote a scalar variable. Perl contains three types of scalars:  Numbers.  Strings.  References.

Chapter 16 Perl Arithmetic Operators Operator Meaning Increment / Decrement - + Unary Minus/Unary Plus ** Exponentiation * / % Multiplication/Division/Modulus + - Addition / Subtraction = **= *= /= %=+= -= Assignment

Chapter 16 The Arithmetic Expressions Page

Chapter 16 Perl Arithmetic Functions Function Meaning abs(x) Absolute value. atan2(x) Arc tangent (in radians). chr(x) Character equivalent of x (ASCII). cos(x) Cosine of x (in radians). exp(x) e x. int(x) Integer equivalent of x (a float). log(x) log e x. rand(x) Random number between 0 and x (fraction). sin(x) Sine of x (in radians) sqrt(x) Square root of x.

Chapter 16 The Sales Tax Page The Sales Tax page uses the int() function.

Chapter 16 Perl String Operators Operator Meaning ++ String Increment =~ !~ Match/Does not match x Repetition. Concatenation = Assignment x= Assignment/Repetition.= Assignment/Concatenation

Chapter 16 The String Operators Page

Chapter 16 Perl String Functions Function Meaning index( string,substr ) Starting index of substr or -1. lc( expr ) Convert expr to all lowercase. lcfirst( expr ) Convert only first letter to lowercase. length( expr ) Return number of characters. ord( string ) Return ASCII value of first character. rindex( string, substr ) Starting index of substr from right or -1 uc( expr ) Convert expr to all uppercase. ucfirst( expr ) Convert only first letter to uppercase.

Chapter 16 The String Functions Page

$string = "O, Happy Dagger!"; print "String: $string \n"; $length = length($string); print "Length: $length \n"; $index1 = index($string, "Dagger", 0); print "Index of Dagger: $index1 \n"; $index1 = index($string, "z"); print "Index of z: $index1 \n"; $string = lc($string); print "Lowercase: $string \n"; $string = uc($string); print "Uppercase: $string \n";