1 / 84

Fundamentals of CGI Programming Using Perl

Fundamentals of CGI Programming Using Perl. Lesson 1: Application Development Fundamentals. Objectives. Explain the application development process Distinguish among various application development environments Identify common application development platforms

Download Presentation

Fundamentals of CGI Programming Using Perl

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Fundamentals of CGI Programming Using Perl

  2. Lesson 1:ApplicationDevelopment Fundamentals

  3. Objectives • Explain the application development process • Distinguish among various application development environments • Identify common application development platforms • Clarify various communication protocols • Determine when to use client-side or server-side scripting

  4. Define a need for a solution Analyze the requirements Create an implementation plan and perform top-level design Perform in-depth design Create the application Test the system Deploy the system Maintain the system The ApplicationDevelopment Process

  5. Platforms,Languages and Protocols • Development platforms • Server-side development technologies • Client-side development technologies • Communication protocols

  6. Client-Side vs. Server-Side Scripting • Performance issues • Security risks

  7. HypertextTransfer Protocol • Passing information with HTTP • HTTP methods

  8. Summary • Explain the application development process • Distinguish among various application development environments • Identify common application development platforms • Clarify various communication protocols • Determine when to use client-side or server-side scripting

  9. Lesson 2:Introduction to CGI and Perl

  10. Objectives • Explain how the Common Gateway Interface works • Describe the GET and POST methods • Describe the benefits of CGI • Describe the benefits of choosing Perl as your CGI scripting language

  11. Web Architecture Overview • Browser, server and script interaction • Common Gateway Interface

  12. What Is CGI? • Common • Supported on almost every platform • Gateway • Gate or conduit that connects clients and servers or server programs • Interface • The manner in which the gateway is used

  13. Why Use CGI? • Two-directional communication • Storage of user-entered data • Portability of code • Browser independence

  14. What Is Perl? • Practical Extraction Report Language

  15. Why Use Perl? • Free license • Smooth installation • Pre-existing programs • Text and file processing capabilities • Strong points from other languages

  16. Summary • Explain how the Common Gateway Interface works • Describe the GET and POST methods • Describe the benefits of CGI • Describe the benefits of choosing Perl as your CGI scripting language

  17. Lesson 3:Creating a Simple Script

  18. Objectives • Discuss the advantages and disadvantages of client-side and server-side scripts • Use scalar variables • Print HTML to the browser using the print statement

  19. Key Concepts and Syntax • Client-side versus server-side scripting • Scalar variables in Perl • Built-in functions • Single and double quotation marks • Using variables in strings • User-defined functions

  20. Key Concepts and Syntax(cont’d) • Printing HTML from a Perl script • Including HTML after the _END_ keyword • Printing HTML using print <<ANYWORD • Printing HTML from a file

  21. Summary • Discuss the advantages and disadvantages of client-side and server-side scripts • Use scalar variables • Print HTML to the browser using the print statement

  22. Lesson 4:Perl Fundamentals

  23. Objectives • Use CGI.pm to examine environment variables • Use Perl arrays and associative arrays • Define list and scalar context • Use pattern matching operators • Write if statements • Create loops

  24. Accessing Environment Variables • Environment variables are stored in an associative array

  25. Using CGI.pm to Access Environment Variables • Simpler CGI.pm syntax • Environment access methods

  26. If Statement • Used exactly as it is used in JavaScript • Can also be used in a unique way at the end of any statement

  27. Logical Expressions • Numeric and string operators

  28. Pattern Matching • Pattern matching operator

  29. Perl Arrays • Holds a list of scalars (numbers of strings) • List context versus scalar context • Initializing scalar variables from an array

  30. Passing Values to Functions • Values that are passed to functions are held in arrays

  31. Associative Arrays • Converting associative arrays to arrays • Using join with arrays and associative arrays • Using split with arrays

  32. Loops • The while loop • The next and last statements • The for loop • The foreach loop • The sort function

  33. Summary • Use CGI.pm to examine environment variables • Use Perl arrays and associative arrays • Define list and scalar context • Use pattern matching operators • Write if statements • Create loops

  34. Lesson 5:Perl File Input and Output Capabilities

  35. Objectives • Open and close files from within scripts • Read and write to sequential files • Read and write to random-access files • Define file modes • Use the diamond operator in scalar and list contexts • Use file tests in conditional statements

  36. File IO Using File Handles • The unless statement • The die statement and the | | operator • The && operator

  37. File Modes • Reading a file • Writing to a file • Appending to a file • Reading and writing to a random-access file

  38. Using Files in Scripts • Writing to a file • Reading from a file using the diamond operator <> • Reading from a file using the read function • Reading and writing to a random-access file • The seek function

  39. Creating a Hit Counter • Every time a page is called, a counter reads and increments the number in the file, and stores it back to the file

  40. Summary • Open and close files from within scripts • Read and write to sequential files • Read and write to random-access files • Define file modes • Use the diamond operator in scalar and list contexts • Use file tests in conditional statements

  41. Lesson 6:Controlling Processing and Output

  42. Objectives • Use the HTML form generation methods of CGI.pm to create HTML pages • Use the param method to retrieve form values • Create a dual-mode form that accepts and generates data depending on how it is accessed • Validate form data and print a missing fields page • Test Perl scripts in offline mode

  43. Incorporating HTML into Perl Using CGI.pm • Methods of CGI.pm include • start_html • end_html • startform A,B,C • endform • submit A • textfield A,B,C,D • button A,B • hidden A,B • header A

  44. Using CGI.pm to Access Form Data • The POST method • Using CGI.pm for GET or POST

  45. ProcessingUser-Entered Data • Using the ReadParse method

  46. Using One File to Createand Process an HTML Form • Perl scripts can operate in two modes • Called from a hyperlink • Called from a form submission

  47. Using Perl toValidate Form Input • Perl scripts commonly validate form data: • Before saving the data • Before processing the data

  48. Summary • Use the HTML form generation methods of CGI.pm to create HTML pages • Use the param method to retrieve form values • Create a dual-mode form that accepts and generates data depending on how it is accessed • Validate form data and print a missing fields page • Test Perl scripts in offline mode

  49. Lesson 7:Saving User-Supplied Data to a File

  50. Objectives • Use the named parameters syntax for CGI.pm methods • Save data to a file in a tab-delimited format • Save data to a file using the save method of the CGI.pm module • Delete and append name-value pairs • Use the substitution pattern-matching operator • Use the &_ variable to simplify scripts

More Related