Serverside Scripting III - PowerPoint PPT Presentation

1 / 63
About This Presentation
Title:

Serverside Scripting III

Description:

To be able to construct programs that interact with MySQL databases. 4. 9.1 Introduction ... to write descriptive comments in programs 'shebang' construct ... – PowerPoint PPT presentation

Number of Views:43
Avg rating:3.0/5.0
Slides: 64
Provided by: ictlabTyi
Category:

less

Transcript and Presenter's Notes

Title: Serverside Scripting III


1
Lecture 9
  • Server-side Scripting III
  • Perl

2
OUTLINE
Introduction Perl String Processing and Regular
Expressions Viewing Client/Server Environment
Variables Form Processing Server-Side
Includes Verifying a Username and Password Using
DBI to Connect to a Database Operator Precedence
Chart
3
Objectives
  • In this lesson, you will learn
  • To understand basic Perl programming.
  • To understand string processing and regular
    expressions in Perl.
  • To be able to construct programs that interact
    with MySQL databases.

4
9.1  Introduction
  • Practical Extraction and Report Language (Perl)
  • One of the most widely used language for Web
    programming

5
9.1  Introduction
Fig. 9.1 Data path of a typical CGI-based
application.
6
9.2  Perl
  • Case sensitive
  • 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
  • print
  • Write text to screen
  • Escape sequence \n
  • Moves output cursor to next line

7
9.2  Perl
  • Interpolation
  • Replace variable with its associated data
  • undef
  • In numeric context
  • Evaluates to 0
  • In a string context
  • Empty string ( )
  • Range operator ( .. )
  • Specifies all values between uppercase A and
    uppercase Z are to replace in array

8
fig9_01.pl(1 of 1)
9
9.2  Perl
10
fig9_02.pl(1 of 2)
11
fig9_02.pl(2 of 2)
12
fig9_03.pl(1 of 2)
13
fig9_03.pl(2 of 2)
14
9.3  String Processing and Regular Expressions
  • Text manipulation
  • Done with a regular expression
  • Series of characters that serves as a
    pattern-matching template
  • String-processing tasks
  • Can be accomplished by using Perls equality and
    comparison operators
  • foreach statement
  • Iterates sequentially through elements
  • Match operator ( m// )
  • Uses regular expressions to search string for
    specified pattern
  • Binding operator
  • Binds whatever is on its left side to a
    regular-expression operator on its right side

15
9.3  String Processing and Regular Expressions
  • Metacharacters
  • Specify patterns or contexts that cannot be
    defined using literal characters
  • Word boundary
  • Boundary between an alphanumeric character and
    something that is not an alphanumeric character
  • modifier
  • Quantifier that instructs Perl to match preceding
    character one or more times

16
fig9_04.pl(1 of 1)
17
fig9_05.pl(1 of 2)
18
fig9_05.pl(2 of 2)
19
9.3  String Processing and Regular Expressions
20
9.3  String Processing and Regular Expressions
21
9.4  Viewing Client/Server Environment Variables
  • Environment variables
  • Contain information about execution environment
    in which a script is being run
  • use statement
  • Instructs Perl programs to include modules
  • Modules
  • Contents of predefined packages
  • import tag standard
  • Import a predefined set of standard functions
  • Key
  • Value name
  • Assigned a value using the arrow operator ( gt )

22
9.4  Viewing Client/Server Environment Variables
  • ENV hash
  • Built-in table in Perl that contains names and
    values of all environment variables
  • Function sort
  • Order array of keys alphabetically

23
fig9_06.pl(1 of 2)
24
fig9_06.pl(2 of 2)
25
9.5  Form Processing
  • 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
  • Retrieves values from a form fields value
  • Business logic (business rules)
  • Design of verifying information
  • Function br
  • Adds a break ( ltbr /gt ) to XHTML page
  • Functions span and div
  • Adds ltspangt and ltdivgt to page respectively

26
fig9_07.html(1 of 3)
27
fig9_07.html(2 of 3)
28
fig9_07.html(3 of 3)
29
(No Transcript)
30
fig9_08.pl(1 of 4)
31
fig9_08.pl(2 of 4)
32
fig9_08.pl(3 of 4)
33
fig25_13.pl(4 of 4)
34
9.6  Server-Side Includes
  • Commands embedded in XHTML documents to allow
    creation of simple dynamic content
  • Written as XHTML comments
  • .shtml file extension (s stands for server)
  • Parsed by server
  • ECHO command
  • Display variable information
  • Keyword VAR
  • Specifies name of the variable
  • EXEC
  • Can be used to run CGI scripts and embed their
    output directly into Web page

35
9.6  Server-Side Includes
  • Diamond operator ltgt
  • Read one line of file referred to by filehandle
    COUNTREAD
  • gt character
  • Write mode
  • Append mode ( gtgt )
  • Appending to the end of a file
  • Function close
  • Terminates connection
  • for structure
  • Iterates
  • Function length
  • Returns length of character string

36
fig9_09.shtml(1 of 3)
37
fig9_09.shtml(2 of 3)
38
fig9_09.shtml(3 of 3)
39
fig9_10.pl(1 of 1)
40
(No Transcript)
41
9.7  Verifying a Username and Password
  • Private Web sites
  • Visible only to certain people
  • Username and password verification
  • chomp
  • Remove newline character at end of line
  • split
  • Divide string into substrings at specified
    separator

42
fig9_11.html(1 of 3)
43
fig9_11.html(2 of 3)
44
fig9_11.html(3 of 3)
45
fig9_12.pl(1 of 3)
46
fig9_12.pl(2 of 3)
47
fig9_12.pl(3 of 3)
48
password.txt(1 of 1)
49
(No Transcript)
50
9.8  Using DBI to Connect to a Database
  • Perl DBI (Database Interface)
  • prepare
  • execute
  • disconnect
  • finish

51
9.8  Using DBI to Connect to a Database
  • Perl DBI (Database Interface), cont.
  • Access different types of databases uniformly
  • Perl Package Manager (PPM)
  • Download and install Perl modules and packages
  • Start PPM
  • Type ppm at command prompt
  • Interactive mode
  • Database handles
  • Create and manipulate connection to database
  • Statement handles
  • Create and manipulate SQL statements to database
  • DBI method connect
  • Connect to database

52
fig9_13.pl(1 of 3)
53
fig9_13.pl(2 of 3)
54
fig9_13.pl(3 of 3)
55
fig9_14.pl(1 of 3)
56
fig9_14.pl(2 of 3)
57
fig9_14.pl(3 of 3)
58
(No Transcript)
59
9.10  Operator Precedence Chart
60
9.10  Operator Precedence Chart
61
9.10  Operator Precedence Chart
62
9.10  Operator Precedence Chart
63
Lecture 9
  • END of Lecture
Write a Comment
User Comments (0)
About PowerShow.com