Skip to:Content
Cover image for PERL and CGI for the world wide web
PERL and CGI for the world wide web
Personal Author:
Visual quickstart guide
2nd ed.
Publication Information:
Berkeley, Calif. : Peachpit Press, 2001


Item Barcode
Call Number
Material Type
Item Category 1
30000004885764 QA76.625 C37 2001 Open Access Book Book

On Order



Perl is one of the most popular scripting languages for adding powerful interactive features to Web pages. Perl lets you place forms on your site that collect and process user input such as comments and product orders; enables visitors to search for information; and can integrate a database into your site, among its many other capabilities.Perl and CGI for the World Wide Web, 2nd Edition: Visual QuickStart Guidefully revised and updated since its original 1998 release, gets users to the core of CGI scripting with Perl. Even first-time programmers will be able to create useful, workable scripts from scratch, or adapt and customize existing scripts to their own needs. Hundreds of screen shots and clear, easy-to-understand directions make this the perfect Perl book for beginners, as well as a handy reference for those with previous programming experience.

Author Notes

Elizabeth Castro is the author of four best-selling editions of HTML for the World Wide Web: Visual QuickStart Guide . She also wrote the best-selling Perl and CGI for the World Wide Web: Visual QuickStart Guide , and XML for the World Wide Web: Visual QuickStart Guide .

Table of Contents

Chapter 1 Introductionp. 13
What Is a Program?p. 14
Why Perl?p. 15
What about CGI?p. 16
Security Issuesp. 17
Perl and HTMLp. 18
About This Bookp. 19
What This Book Is Notp. 20
What's Newp. 21
The Perl and CGI VQS Guide Web Sitep. 22
Chapter 2 Perl Building Blocksp. 23
Perl Datap. 24
Operators and Functionsp. 28
Quotation Marksp. 30
Quoting without Quotesp. 31
Statement, Blocks, and Scopep. 32
Declaring Private Variablesp. 34
The Shebang Linep. 35
Creating a Perl CGI Scriptp. 36
Creating Output for a Browserp. 38
Documenting Your Scriptp. 39
Checking the Script's Syntaxp. 40
Chapter 3 About Servers, Perl, and CGI.pmp. 41
What Is a Server?p. 42
The Importance of Directoriesp. 44
Ask Your Web Host!p. 46
Getting a Perl Interpreterp. 47
Getting CGI.pmp. 48
Chapter 4 Running Perl CGI on a Unix Serverp. 49
Which Perl Are They Running?p. 50
What About 51
Installing Scripts on Unix Serversp. 52
Uploading Your Scriptp. 53
Changing Permissionsp. 56
Testing Your Unix Serverp. 58
Chapter 5 Testing Scripts Locally on Windowsp. 59
Installing the Xitami or Sambar Serverp. 60
Installing Personal Web Serverp. 62
Installing IIS on Windows 2000p. 64
Displaying File Extensionsp. 65
Testing Your Server (Part 1)p. 66
Installing the Perl Interpreterp. 67
Installing CGI.pmp. 68
Installing Scripts on Windows Serversp. 69
Testing Your Server (Part II)p. 70
Chapter 6 Testing Scripts Locally on the Macp. 71
Installing Personal Web Sharingp. 72
The Root Web Directoryp. 73
Carefully Sharing the Root Web Directoryp. 74
Starting the Web Sharing Serverp. 76
Testing the Server (Part 1)p. 77
Installing MacPerlp. 78
Installing CGI.pmp. 79
Installing Scripts on Mac Serversp. 80
Testing Your Server (Part II)p. 81
Chapter 7 Getting Data from Visitorsp. 83
Labeling Incoming Datap. 84
Creating a Formp. 86
Creating Text Boxesp. 87
Creating Password Boxesp. 88
Creating Larger Text Areasp. 89
Creating Radio Buttonsp. 90
Creating Checkboxesp. 91
Creating Menusp. 92
Creating the Submit Buttonp. 93
Resetting the Formp. 94
Using an Image to Submit Datap. 95
Creating a Link to a Scriptp. 96
Using a Link to Input Data to a Scriptp. 97
Chapter 8 Environment Variablesp. 99
Your Visitor's Browser and Platformp. 100
Viewing Available Environment Variablesp. 101
Storing Data from Environment Variablesp. 102
Chapter 9 Getting Data into the Scriptp. 103
Getting Single-Valued Form Datap. 104
Getting Multiple-Valued Form Datap. 105
Getting All the Form Element's Namesp. 106
Getting All the Names and Valuesp. 107
Chapter 10 Simple Operations with Scalarsp. 109
Assigning a Value to a Scalar Variablep. 110
Multiplying, Dividing, Adding, Subtractingp. 112
Using More Than One Operatorp. 113
Raising a Number to an Exponential Powerp. 114
Using Mathematical Functionsp. 115
Getting the Remainder of a Divisionp. 116
Connecting Strings Togetherp. 117
Repeating a Stringp. 118
Operating and Assigning in One Stepp. 119
Incrementing (or Decrementing) a Variablep. 120
Chapter 11 Conditionals and Loopsp. 121
Comparing Numbersp. 122
Comparing Stringsp. 123
Evaluating Conditions without Comparisonsp. 124
Testing Two or More Comparisons at a Timep. 125
Creating a Basic Conditional Statementp. 126
Adding Options for False Conditionsp. 127
Adding Multiple, Independent Conditionsp. 128
Using Unlessp. 129
Repeating a Block for Each Item in an Arrayp. 130
Loading the Default Variablep. 131
Repeating a Block While a Condition Is Truep. 132
Repeating a Block While a Condition Is Falsep. 133
Executing the Block at Least Oncep. 134
Repeating a Block a Given Number of Timesp. 135
Nesting Conditional Statementsp. 136
Skipping a Loop Iterationp. 137
Jumping out of a Loop Altogetherp. 138
Chapter 12 Working with Arraysp. 139
Assigning a List to an Array Variablep. 140
Referring to a Particular Item in an Arrayp. 142
Referring to Multiple Items from an Arrayp. 144
Adding or Replacing an Item in an Arrayp. 145
Adding to the End or Beginning of an Arrayp. 146
Removing the Last Item from an Arrayp. 148
Removing the First Item from an Arrayp. 149
Replacing More Than One Item in an Arrayp. 150
Finding the Length of an Arrayp. 152
Modifying All the Members of an Arrayp. 153
Sorting Arraysp. 154
Reversing the Order of an Array's Contentsp. 155
Chapter 13 Subroutinesp. 157
Creating a Simple Subroutinep. 158
Using a Simple Subroutinep. 159
Creating a Subroutine That Takes Inputp. 160
Calling a Subroutine That Takes Inputp. 161
Using a Subroutine's Return Valuep. 162
Setting the Return Value Manuallyp. 163
Storing Subroutines in an External Filep. 164
Calling Subroutines from an External Filep. 165
Chapter 14 Working with Hashesp. 167
Assigning a List to a Hashp. 168
Getting a Value by Using a Keyp. 169
Adding or Replacing a Key-Value Pairp. 170
Getting Several Values Using Keysp. 171
Getting All of a Hash's Keysp. 172
Getting All of a Hash's Valuesp. 173
Getting Each Key and Value in a Hashp. 174
Getting the Pairs in a Specified Orderp. 176
Removing Key-Value Pairsp. 178
Checking to See If a Key Existsp. 179
Chapter 15 Analyzing Datap. 181
Finding Somethingp. 182
Finding and Replacingp. 183
Seeing and Using What Was Foundp. 184
Splitting a Value into Piecesp. 185
Constructing Search Patternsp. 186
Tips for Constructing Search Patternsp. 187
Matching a Single Characterp. 188
Matching a String of Charactersp. 189
Matching a Character from a Groupp. 190
Matching a Character That's Not in the Groupp. 191
Using Class Shorthandsp. 192
Limiting the Locationp. 193
Choosing How Many to Matchp. 195
Curbing a Quantifier's Greedinessp. 200
Matching One Element or Anotherp. 201
More on Using What You Already Matchedp. 202
Chapter 16 Remembering What Visitors Tell Youp. 205
About Hidden Fieldsp. 206
Adding Hidden Fields to a Formp. 207
Storing Collected Data in a Hidden Fieldp. 208
About Cookiesp. 210
Looking at Your Browser's Cookiesp. 211
Sending a Cookiep. 212
Setting a Cookie's Expiration Datep. 214
Limiting a Cookie to a Domainp. 215
Limiting a Cookie to a Part of Your Serverp. 216
Limiting Cookies to Secure Connectionsp. 217
Reading and Using a Cookiep. 218
How (and Why) Visitors Refuse Cookiesp. 220
Chapter 17 Formatting, Printing, and HTMLp. 221
Formatting Output with Perlp. 222
Creating a Format Pattern for Integersp. 223
Creating a Format Pattern for Non-Integersp. 224
Creating a Pattern for Stringsp. 225
Changing the Casep. 226
Changing Charactersp. 227
Finding the Length of a Stringp. 228
Finding Where Something Is in a Stringp. 229
Extracting One String from Anotherp. 230
Cleaning up the End of a Stringp. 231
Formatting Output with HTMLp. 232
Printing Several Lines at a Timep. 234
Simplifying Paths to Images and Linksp. 235
Outputting Data in a Tablep. 236
Chapter 18 Securityp. 237
Reading the Security FAQsp. 238
The Problem with Visitor Inputp. 239
Protecting Calls to the Systemp. 240
Limiting Access to Filesp. 241
Using to Limit Incoming Datap. 242
Keeping Information to Yourselfp. 243
Avoiding Tainted Datap. 244
Cleaning and Using Outside Datap. 245
Chapter 19 Files and Directoriesp. 247
Opening a Filep. 248
Verifying File and Directory Operationsp. 250
Writing to an External Filep. 251
Getting Exclusive Access to a Filep. 252
Reading Data from an External Filep. 253
Closing a Filep. 254
Renaming a Filep. 255
Removing a Filep. 256
Checking a File's Statusp. 257
Opening a Directoryp. 258
Reading the Contents of a Directoryp. 259
Closing a Directoryp. 260
Changing the Working Directoryp. 261
Creating a Directoryp. 262
Changing Permissions from within a Scriptp. 263
Removing a Directoryp. 264
Getting Ready to E-mail Outputp. 265
Sending Output via E-mailp. 266
Chapter 20 Uploading Filesp. 269
Creating a Form for Uploading Filesp. 270
Getting the Name of the Uploaded Filep. 271
Finding out a File's MIME Typep. 272
Specifying Where the File Should Be Savedp. 273
Reading in and Limiting Uploaded Filesp. 274
Appendix A Debuggingp. 277
Checking the Easy Stuffp. 278
Creating an Error Subroutinep. 280
Using Perl's Error Reportingp. 281
Viewing the System Error Logp. 282
Isolating the Problemp. 283
Following a Variable's Progressp. 284
Appendix B Using Other Folks' Scriptsp. 285
Using Other Folks' Scriptsp. 286
Getting Other People's Scriptsp. 287
Expanding Compressed Scriptsp. 288
Configuring Borrowed Scriptsp. 289
Customizing Borrowed Scriptsp. 290
Appendix C Permissions on Unixp. 291
Figuring out the Permissions Codep. 292
Default Permissionsp. 293
Who's the Owner?p. 294
Appendix D Unix Essentialsp. 295
Telnetting to Your Unix Serverp. 296
Executing Commands in Unixp. 298
Dealing with Paths in Unixp. 299
Changing the Working Directoryp. 302
Finding out Where You Arep. 303
Listing Directory Contentsp. 304
Eliminating Filesp. 305
Creating and Eliminating Directoriesp. 306
Decompressing Tar and Zipped Filesp. 307
Getting Help with Unixp. 308
Appendix E Perl and CGI Resourcesp. 309
Text Editorsp. 310
Telnet Programsp. 311
Other Folks' Scriptsp. 312
Learning Morep. 313
Indexp. 315
Go to:Top of Page