Thursday, October 14, 2010

CGI Tutorial: Chapter cgilib cases


A simple request form to read and process the data cgilib.pl example:

#! / Usr / bin / perl

sub readGetData (
Local variable queryString # specify the transfer function for the parameters of preservation and
local (* queryString) = @ _ if @ _;
# Read environment variable QUERY_STRING value is assigned to the variable $ queryString
$ QueryString = $ ENV ("QUERY_STRING");
return 1;
)

sub readPostData (
local (* queryString) = @ _ if @ _;
local ($ contentLength);
# Read the value of environment variable CONTENT_LENGTH
$ ContentLength = $ ENV ("CONTENT_LENGTH");
# Check if there are data
if ($ contentLength) (
# STDIN to read from the device contentLength the length of characters assigned to $ queryString
read (STDIN, $ queryString, $ contentLength);
)
return 1;
)

sub readData (
local (* queryString) = @ _ if @ _;
# Read environment variables REQUEST_METHOD
$ RequestType = $ ENV ("REQUEST_METHOD");

# If the request method is GET use the function readGetData
# Otherwise, if the request method is POST, use the function readPostData
if ($ requestType eq "GET") (
& ReadGetData (* queryString);
)
elsif ($ requestType eq "POST") (
& ReadPostData (* queryString);
)
return 1;
)

sub DecodeData (
local (* queryString) = @ _;
# Convert spaces to plus
$ QueryString = ~ s / + / / g;
# Convert hexadecimal characters
$ QueryString = ~ s /%(..)/ pack ("c", hex ($ 1)) / ge;
return 1;
)

sub parseData (
local (* queryString, * formData) = @ _ if @ _;
local ($ key, $ value, $ curString, @ tmpArray);

& As the delimiter # to convert the string to key - value pairs
@ TmpArray = split (/&/,$ queryString);

# Inner loop in the array @ tmpArray
foreach $ curString (@ tmpArray) (
# = As a separator to separate the key - value pairs
($ Key, $ value) = split (/=/,$ curString);
# Decoding
& DecodeData (* key);
& DecodeData (* value);
# The key and the value added to the dictionary
$ FormData ($ key) = $ value;
)
return 1;
)

1;
# End of file cgilib.pl

Usage:

To use this library must include the following statement:
# Require "cgilib.pl";
Form data processing:
% DataDict = ();
& ReadData (* data);
& ParseData (* data, dataDict);
Data Dictionary:
while (($ key, $ value) = each (% dataDict)) (
print $ key ,"=",$ value, "nn";
)






Recommended links:



Learning organization's five STATE



Comparison Reference Tools



Processing performance appraisal fairness AND human factors in the relationship between



UNSTOPPABLE P2P



3DS Max 7 Mental Ray renderer whole strategy: global illumination



Guide To Fully Experience The Still-mail (a) - Attachment



Desktop Directory



How to write better bug REPORT [2]



MKV to FLV



Premier Web SERVERS



RMVB to MP4



Four Common Questions About Computer Animation



Ma: I May A Little Crazy But Not Stupid



Full-width half-angle switching (FIVE-STROKE input)



Directory Web Development



TS to MPG



Kai-fu Lee Entrepreneurs Need To Have Sufficient "relentless"



No comments:

Post a Comment