Download presentation
Presentation is loading. Please wait.
Published byStanley Ward Modified over 8 years ago
1
Chapter 18 The HTML Tag <FORM NAME = " form name " opt ACTION = " URL " METHOD = "POST | GET" ENCTYPE = " mimeType " opt TARGET = " Target Page or Frame " opt onSubmit = " eventHandler " opt onReset = " eventHandler " opt > formElement 1.... formElement n Name of Perl Script Transmission Method
2
Chapter 18 URLencoding Symbol Meaning & The ampersand separates the form's fields. = The assignment operator separates a field name from the user's response. + Plus signs are used to transmit spaces. % Hexadecimal notation is used to represent non-alphanumeric characters.
3
Chapter 18 URLencoding When the GET method is used the URLencoded information appears after the ?
4
Chapter 18 The GET Method The GET method is used to transmit data when the data string does not exceed 256 characters. The text field is only 12 characters. A Submit button is used to signal completion of the form.
5
Chapter 18 The GET Method The GET method passes the data through the QUERY_STRING key of the ENV hash.
6
Chapter 18 Decoding: GET Method 1. Obtain the Form Data: $form_data = $ENV{‘QUERY_STRING’}; 2. Convert ASCII Characters: $form_data =~ s/%([\dA-Fa-f][\dA-Fa-f])/ pack ("C", hex ($1))/eg; 3. Separate Field Name and Data: ($field_name, $name) = split (/=/, $form_data); 4. Remove Suspicious Characters: $name =~ s/[;<>\(\)\{\}\*\|'`\&\$!#:"\\]/\ $1/g; 5. Convert Plus Sign to Spaces: $name =~ s/[+]/\ $1/g;
7
Chapter 18 The POST Method The POST method displays a Security Warning box prior to submission of the form. A Submit button is used.
8
Chapter 18 The POST Method The POST method passes the data through the standard input device. The CONTENT_LENGTH key of the ENV hash is used to obtain the data’s size.
9
Chapter 18 Decoding: POST Method 1. Obtain the Form Data: $form_size = $ENV{'CONTENT_LENGTH'}; read (STDIN, $form_data, $form_size); 2. Convert ASCII Characters: $form_data =~ s/%([\dA-Fa-f][\dA-Fa-f])/ pack ("C", hex ($1))/eg; 3. Separate Field Name and Data: ($field_name, $name) = split (/=/, $form_data); 4. Remove Suspicious Characters: $name =~ s/[;<>\(\)\{\}\*\|'`\&\$!#:"\\]/\ $1/g; 5. Convert Plus Sign to Spaces: $name =~ s/[+]/\ $1/g;
10
Chapter 18 The if…else Statement if ( expression ) { statement 1 ; statement n ; } elsif ( expression ) optional { statement 1 ; statement n ; } else optional { statement 1 ; statement n ; } Perl uses the if…else statement for selection. A block of code, as denoted by {}, is required for each clause. Notice Perl’s use of elsif.
11
Chapter 18 The if..else Statement The Test Score page uses an if..else statement to determine the grade.
12
Chapter 18 The if…else Statement if ($per_correct >= 90 && $per_correct <= 100) {print "Grade: A \n"} elsif ($per_correct >= 80 && $per_correct < 90) {print "Grade: B \n"} elsif ($per_correct >= 70 && $per_correct < 80) {print "Grade: C \n"} elsif ($per_correct >= 60 && $per_correct < 70) {print "Grade: D \n"} else {print "Grade: F \n"} The if…else statement used to determine the grade.
13
Chapter 18 The unless Statement unless ( expression ) { statement 1 ; … statement n ; } Perl provides an unless statement that represents the inverse of an if statement without elsif or else clauses.
14
Chapter 18 The unless Statement The unless statement prints a message only when the pH is too high for Azaleas. unless($ph <= 5.5) {print "Sorry. Your pH is too high for Azaleas.\n"}
15
Chapter 18 Statement Modifiers statement if ( expression ); satement unless ( expression ); statement while ( expression ); statement until ( expression ); Perl provides four statement modifiers that we can use when we only need to execute a single statement.
16
Chapter 18 Statement Modifiers print "Small #($n) \n" if ($n <= 100); print "Small #($n) \n" unless ($n > 100); $n=10; print "Count $n \n" while ($n-- >0); $n=10; print "Count $n \n" until ($n-- ==0); Examples of Perl’s statement modifiers.
17
Chapter 18 Matching Operators Matching $ scalar =~ m/ regex / options $ scalar =~ / regex / options Not Matching $ scalar !~ m/ regex / options $ scalar !~ / regex / options Perl contains matching and Not matching operators
18
Chapter 18 Substitution/Transliteration Substitution $ scalar =~ s/ pattern / replacement / options Transliteration $ scalar =~ tr/ pattern / replacement / options $ scalar =~ y/ pattern / replacement / options Perl contains substitution and transliteration operators.
19
Chapter 18 Splitting and Searching Splitting ( scalar list ) = split(/ pattern /, $ scalar ); @ array = split(/ pattern /, $ scalar ); Searching @ array = grep(/ pattern /, @ array ); Perl contains splitting and searching functions.
20
Chapter 18 Regular Expressions Regular Expressions are created with: Quantifiers which are used to control repetition. Constructs which are built-in pattern sets. The regular expression object also contains methods for searching and matching.
21
Chapter 18 Quantifiers QuantifierMeaning * Match zero or more times. + Match one or more times. ? Match zero or one. { n } Match exactly n times. { n,} Match at least n times. { n, m } Match at least n times but no more than m times ( ) Override precedence [ ] Pattern set \ CharacterMatch a meta character. ^ Match at beginning $ Match at end. Match any character except new line | Match either character on left or on right.
22
Chapter 18 Constructs ConstructMeaning \d Match digits \D Do not match digits \w Match Word: letters, digits, underscore \W Do not match words \s Match "white space" (space, \n, \t, \r, \f) \S Do not match white space \b Match Word boundary (letters only) \B Do not Match Word boundary (letters only)
23
Chapter 18 The Regular Expressions Page
24
if ($hash{'string'} =~ /$hash{'expr'}/gi) { print "A match occured. \n"; print "Before Match: $` \n"; print "Matched String: $& \n"; print "After Match: $' \n"; } else {print "No match occured. \n"; } print " Parenthesized Expressions \n"; print "\$1: $1 \n"; print "\$2: $2 \n"; print "\$3: $3 \n"; print "\$4: $4 \n";
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.