![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Perl CGl Programming: No experience required.
Lists of StringsWhen you load strings into an array, they need to be distinguished somehow. The Perl convention departs slightly from what we have learned so far, which is to enclose strings of characters in double quotes. This can be done with lists, but it is considered more correct to delimit lists of strings with single quotes (). Table 1.2 illustrates some of the things you can do with strings.
Perl lists have numerous other features, but well save those for when we approach more complex programming topics. For now, you should know what a list is, how to initialize it, and how to access one of its members.
Perl and the Common Gateway InterfaceYouve learned a little about the Perl programming language. But how does it fit into the World Wide Web? The Common Gateway Interface (CGI) is the key. CGI has been used for many years as a facility for passing information from a Web page to a program that can process the information. CGI, despite what many programmers put on their resumes, is not a programming language. It is, as the name states explicitly, an interface. It allows you to write a program that will take all of its input from an HTML document, a page on the World Wide Web, and do something with that input. You can regard CGI as a kind of pipeline between your Web page and a Perl program (see Figure 1.9): Whatever is entered on the page is available to your program through CGI.
HTML is quite good at describing how a Web page should look in a browser, but the language all by itself has virtually no facilities for processing information or even making rudimentary decisions.
When you run a Perl program from the command line, it takes its input, generally, from you, at your keyboard, and it sends its output, generally, back to you, at the screen. CGI reroutes those standard conventions. The Perl programs input comes from the Web page. Most importantly, CGI sends your programs output back to the Web server. If the output happens to be formatted correctly in HTML, the server will put it out as an HTML document to whatever browser is connected to it. In other words, a print statement from within your Perl program will be printing to the Web server, not the screen (see Figure 1.10).
This is a difficult concept for many neophytes to grasp, but it is the foundation of using CGI as a pipeline between Perl and HTML. You can draw a Web page from a Perl program. And, because Perl is a fully functional programming language, rather than a markup language such as HTML, you can decide within your program what to draw based on what has been entered in the page and sent to you. Of course, this facility isnt limited to Perl. You can interface with CGI using any program written in any language (provided, of course, that it will run on your computer!). Indeed, there may be occasions when you need the brute force of C/C++ or some other high-level compiled language to tackle some process that would bring your Web server to its knees if the program were written in Perl. For example, a program that does a lot of heavy number crunching would be much more efficient in C or C++ than in Perl. Those occasions will be rare, however. Most of what you need to do can be accomplished more easily from a Perl script than from a compiled program. Additionally, your Perl program wont have to be rewritten and recompiled if you move to another operating system or computer platform.
|
![]() |
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. |