Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter Nine Perl and CGI Programming. 2 Objectives Basic features of Perl language Set up an HTML Web page Use Perl and CGI scripts to make your web.

Similar presentations


Presentation on theme: "Chapter Nine Perl and CGI Programming. 2 Objectives Basic features of Perl language Set up an HTML Web page Use Perl and CGI scripts to make your web."— Presentation transcript:

1 Chapter Nine Perl and CGI Programming

2 2 Objectives Basic features of Perl language Set up an HTML Web page Use Perl and CGI scripts to make your web pages interactive

3 3 Perl is a script language – –Elements of csh, sh, awkExample: #! /usr/bin/perl # example of perl script print(“hello world\n”); Introduction to Perl

4 4 Variables Scalar $word = “test” print(“here it is: $word \n”); Array @list = ("one", "two", "three"); print("here it is: $list[0]\n"); print("here it is: $list[1]\n"); print("here it is: $list[2]\n");

5 5 Variables Hash %animals = ("cat",10,"dog",12,"fish",23); print("1: $animals{'cat'}\n"); print("2: $animals{'dog'}\n"); print("3: $animals{'fish'}\n");

6 6 Command line arguments $ARGV[0], $ARGV[1], … print("$ARGV[0], $ARGV[1]\n"); With a loop: $size = @ARGV; for ($i = 0; $i < $size; $i++) { print("$ARGV[$i]\n"); }

7 7 Reading Input Standard input print("enter a number: "); $number = ; print("here it is: $number");

8 8 Reading from a File if (!open(FILE, "$ARGV[0]")) { print("cannot open: $ARGV[0]\n"); print("cannot open: $ARGV[0]\n");} while ($line = ) { print("$line"); print("$line");}

9 9 Setting Up a Web Page Web pages can be created using HTML (Hypertext markup Language) HTML is a format for creating documents with embedded codes known as tags and when the document is viewed in a Web browser, the tags give the document special properties After using HTML to create a Web page, the page is published on a Web server, this allows others to access the document via the Internet

10 10 Creating a Web Page HTML documents are created by typing its text and the desired embedded tags There are two parts to the HTML code –The head contains the title, which appears on the top bar of the browser window –The body defines what appears within the browser window

11 11 CGI Overview CGI (Common Gateway Interface) is a protocol, or set of rules, governing how browsers and servers communicate Scripts that send or receive information from a server need to follow the CGI protocol Perl is the most commonly used language for CGI programming Perl scripts are written to get, process, and return information through Web pages

12 12 Perl Libraries Libraries of functions: use CGI qw(:standard); print(header); print(start_html("Hello World")); print h2("Test Website"); print(end_html);

13 13 Setting up a Web Page Create subdirctory public_html add files: index.htmlten.cgi

14 14 Interactive Web Page <html><head> COP 3344 COP 3344 <body> User Inquiry User Inquiry Enter your name: </form></body></html>

15 15 Interactive Web Page

16 16 Interactive Web Page #! /usr/bin/perl # example perl script use CGI qw(:standard); print(header); print(start_html("Anser Page")); print h2("Answer Page"); print("Welcome: ", param('userid')); print(end_html);

17 17 Interactive Web Page

18 18 Chapter Summary Perl is a powerful scripting language Perl scripts are used to create web pages An HTML document contains two parts: a head and a body CGI is a protocol or set of rules governing how browsers and servers communicate


Download ppt "Chapter Nine Perl and CGI Programming. 2 Objectives Basic features of Perl language Set up an HTML Web page Use Perl and CGI scripts to make your web."

Similar presentations


Ads by Google