Chapter 25 Perl and CGI (Common Gateway Interface)

Slides:



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

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Introduction to Ruby.
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Introducing JavaScript
A Guide to Unix Using Linux Fourth Edition
Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
 2005 Pearson Education, Inc. All rights reserved Introduction.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
1 Outline 13.1Introduction 13.2A Simple Program: Printing a Line of Text in a Web Page 13.3Another JavaScript Program: Adding Integers 13.4Memory Concepts.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
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.
XP 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial 10.
Perl Basics A Perl Tutorial NLP Course What is Perl?  Practical Extraction and Report Language  Interpreted Language Optimized for String Manipulation.
Guide To UNIX Using Linux Third Edition
JavaScript, Third Edition
2440: 141 Web Site Administration Web Server-Side Programming Professor: Enoch E. Damson.
Introduction to scripting
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 8: Perl Basics Fundamentals of Web Programming.
 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.
Introduction to PHP. PHP PHP is the Hypertext Pre-processor –Script language –Embedded into HTML –Runs as Apache module –Can use DB (MySQL, Oracle, Microsoft.
August Chapter 1 - Essential PHP spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information Science and Technology.
Using Data Active Server Pages Objectives In this chapter, you will: Learn about variables and constants Explore application and session variables Learn.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
JavaScript, Fifth Edition Chapter 1 Introduction to JavaScript.
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
CMPS 211 JavaScript Topic 1 JavaScript Syntax. 2Outline Goals and Objectives Goals and Objectives Chapter Headlines Chapter Headlines Introduction Introduction.
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.
Input, Output, and Processing
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
4 1 Array and Hash Variables CGI/Perl Programming By Diane Zak.
Open Source Software Unit – 3 Presented By Mr. R.Aravindhan.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
Introduction.  The scripting language most often used for client-side web development.  Influenced by many programming languages, easier for nonprogrammers.
3 1 Sending Data Using an Online Form CGI/Perl Programming By Diane Zak.
7 1 User-Defined Functions CGI/Perl Programming By Diane Zak.
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
 2000 Deitel & Associates, Inc. All rights reserved. Outline 8.1Introduction 8.2A Simple Program: Printing a Line of Text in a Web Page 8.3Another JavaScript.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Perl Chapter 5 Hashes. Outside of world of Perl, know as associative arrays Also called hash tables Perl one of few languages that has hashes built-in.
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
4. Javascript M. Udin Harun Al Rasyid, S.Kom, Ph.D Lab Jaringan Komputer (C-307) Desain.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
 2001 Prentice Hall, Inc. All rights reserved. Chapter 7 - Introduction to Common Gateway Interface (CGI) Outline 7.1Introduction 7.2A Simple HTTP Transaction.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Fluency with Information Technology Third Edition by Lawrence Snyder Chapter.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
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.
Dept. of Animal Breeding and Genetics Programming basics & introduction to PERL Mats Pettersson.
PHP Tutorial. What is PHP PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages.
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
PHP using MySQL Database for Web Development (part II)
Web Database Programming Using PHP
Chapter 7 - Introduction to Common Gateway Interface (CGI)
Chapter 6 JavaScript: Introduction to Scripting
Web Database Programming Using PHP
PHP (PHP: Hypertext Preprocessor)
Introduction to Scripting
Intro to PHP & Variables
JavaScript an introduction.
WEB PROGRAMMING JavaScript.
INFO/CSE 100, Spring 2005 Fluency in Information Technology
PHP.
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
Tutorial 10: Programming with javascript
PHP an introduction.
23 PHP.
Presentation transcript:

Chapter 25 Perl and CGI (Common Gateway Interface)

Outline Introduction Introduction First program in Perl First program in Perl Variables Variables Scalars and Their Operations Scalars and Their Operations String Processing String Processing Fundamentals of Arrays Fundamentals of Arrays Hashes Hashes Viewing Environment Variables Viewing Environment Variables Form Processing Form Processing

Introduction Practical Extraction and Report Language (Perl) Practical Extraction and Report Language (Perl) –One of the most widely used language for Web programming Common Gateway Interface (CGI) Common Gateway Interface (CGI) –Standard interface through which users interact with applications on Web servers –Provides way for clients to interact with applications on Web server –CGI script Can be written in many different languages Can be written in many different languages Perl is the most commonly used language for CGI Perl is the most commonly used language for CGI

Introduction Data path of a typical CGI-based application.

Introduction Perl is case sensitive Perl is case sensitive A name must begin with a letter; any number of letters, digits, or underscore characters can follow A name must begin with a letter; any number of letters, digits, or underscore characters can follow By convention, names of variables use only lowercase letters By convention, names of variables use only lowercase letters Comment character ( # ) Comment character ( # ) –Instruct interpreter to ignore everything on current line following # –Allows programmers to write descriptive comments in programs –shebang construct ( #! ) Indicates the path to the Perl interpreter Indicates the path to the Perl interpreter

First Program in Perl

Variables Variables are implicitly declared Variables are implicitly declared A scalar variable that has not been assigned a value has the value undef A scalar variable that has not been assigned a value has the value undef –In numeric context Evaluates to 0 Evaluates to 0 –In a string context Empty string () Empty string (" ")

Scalars and Their Operations Numeric Operators – –Like those of C, Java, etc. String Operators – –Catenation - denoted by a period e.g., If the value of $dessert is "apple", the value of $dessert. " pie" is "apple pie" – –Repetition - denoted by x e.g., If the value of $greeting is "hello ", the value of $greeting x 3 is "hello hello hello "

fig25_04.pl (1 of 2)

String Processing Perl has two kinds of string literals, those delimited by double quotes and those delimited by single quotes – –Single-quoted literals cannot include escape sequences – –Double-quoted literals can include them – –Names embedded in double-quoted string literals are interpolated – –e.g., If the value of $salary is 47500, the value of "Jack makes $salary dollars per year " is "Jack makes dollars per year"

String Processing Text manipulation Text manipulation –Done with a regular expression Series of characters that serves as a pattern-matching template Series of characters that serves as a pattern-matching template String-processing tasks String-processing tasks –Can be accomplished by using Perls equality and comparison operators foreach statement foreach statement –Iterates sequentially through elements

fig25_06.pl (1 of 1)

Fundamentals of Arrays Perl arrays store only scalar values, which can store strings, numbers, and references Perl arrays store only scalar values, which can store strings, numbers, and references A list is an ordered sequence of scalar values A list is an ordered sequence of scalar values –Range operator (.. ) can be used to create a list = (A.. Z) A list literal that has only scalar names can be the target of a list assignment A list literal that has only scalar names can be the target of a list assignment –e.g. ($one, $two, $three) = (1, 2, 3); An array is a variable that can store a list An array is a variable that can store a list

Fundamentals of Arrays Array names all begin with at signs Array names all begin with at signs Arrays can be assigned other arrays or list literals Arrays can be assigned other arrays or list literals = (2, 4, 6, If an array is used where a scalar is expected, the length of the array is used If an array is used where a scalar is expected, the length of the array is used = (1, 55, 193); $len # $len now has the value 3 $len # $len now has the value 3 When an array element is referenced or assigned, the name is a scalar name When an array element is referenced or assigned, the name is a scalar name –e.g. $list[3] = 17; $age = $list[1]; The length of an array is dynamic; it is always the highest subscript that has been assigned, plus 1 The length of an array is dynamic; it is always the highest subscript that has been assigned, plus 1

fig25_05.pl (1 of 2)

Hashes Differ from arrays in two fundamental ways: Differ from arrays in two fundamental ways: 1. Arrays use integers as indices, hashes use strings 1. Arrays use integers as indices, hashes use strings 2. Array elements are ordered, hash elements are not 2. Array elements are ordered, hash elements are not Hash names begin with percent signs (%) Hash names begin with percent signs (%) –List literals are used to initialize hashes –Can be comma-separated values e.g. %hash1 = ("Monday", 10451, "Tuesday", 10580); e.g. %hash1 = ("Monday", 10451, "Tuesday", 10580); –Or, implication symbols can be used between a key and its value e.g. %hash2 = ("Monday" => 10451, "Tuesday" => 10580); e.g. %hash2 = ("Monday" => 10451, "Tuesday" => 10580); Subscripts are keys (strings) placed in braces Subscripts are keys (strings) placed in braces e.g. $s = $salaries{"Joe Schmoe"}; e.g. $s = $salaries{"Joe Schmoe"}; $salaries{"Michel Angelo"} = ; $salaries{"Michel Angelo"} = ;

Hashes Elements can be deleted with delete Elements can be deleted with delete –e.g. delete $salaries{"Bill Clinton"}; Use exists to determine whether a key is in a hash Use exists to determine whether a key is in a hash –e.g. if (exists $salaries{"George Bush"}) …

Viewing Environment Variables Environment variables Environment variables –Contain information about execution environment in which a script is being run %ENV hash %ENV hash –Built-in table in Perl that contains names and values of all environment variables use statement use statement –Instructs Perl programs to include modules –Modules Contents of predefined packages Contents of predefined packages – import tag :standard Import a predefined set of standard functions Import a predefined set of standard functions –Key Value name Value name Assigned a value using the arrow operator ( => ) Assigned a value using the arrow operator ( => )

fig25_11.pl (1 of 2)

Form Processing XHTML forms XHTML forms –Enable Web pages collect data from users and send to Web server for processing by server-side programs and scripts –Function param Part of Perl CGI module Part of Perl CGI module Retrieves values from a form fields value Retrieves values from a form fields value –Function br Adds a break ( ) to XHTML page Adds a break ( ) to XHTML page –Functions span and div Adds and to page respectively Adds and to page respectively

fig25_12.html (1 of 3)

fig25_12.html (2 of 3)

fig25_12.html (3 of 3)

fig25_13.pl (2 of 4)

fig25_13.pl (3 of 4)