![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Perl CGl Programming: No experience required.
How Perl Programs RunIn a technical sense, the Perl interpreter is a language compiler that doesnt write its translated output to a file on the disk. Its output file is the screen, which is called standard output or stdout in systems parlance. If a program name is given on the command line, the interpreter first checks the validity of each line, dumping out error messages for incorrect code and stopping if it finds any. If your program passes muster, the interpreter executes each of its lines of code. One of the convenient aspects of doing it this way is that you find out immediately if your program does something wrongand programs inevitably do! Most developers work on windowed systems, and they run the text editor with their Perl program code in one window and keep the command-line screen in another (see Figure 1.6). It is then quite easy to pop from window to window, writing and fixing code in the text editor and testing the code from the command line. With Perl, you get all your errors at once, and that speeds up the coding process. With a compiled language such as C or C++, you have to write the code, compile it, fix any errors that have cropped up in the compilation, compile it again, link it to the external libraries it needs, thenwhew!run it and see what errors occur there. Then you get to start all over again. Its little wonder that Perl has become so popular!
Dissecting the Hello ExampleWe have briefly covered the first line in the program. Well now take apart this line, #!/usr/bin/perl, piece by piece:
The Heart of the Program: print We have used only one real Perl function in this short programprint. This function is a real workhorse, especially in Web programming, where you will use Perl to construct HTML pages. print is a function that you very likely will use in every program you write. How does print work? Well go into a detailed description later, because print can do a lot. For now, lets look at what it does in hello.pl: print "Hello, World!", "\n"; The unadorned print, as we have used it in the example program, takes a list of strings; that is, text enclosed by quotation marks, as its arguments, or parameters.
In this case, we are telling print that we want it to print the phrases Hello World! and \n to the screen. Notice that the two phrases, which are the print functions arguments, are separated by a comma. It is also important that the line ends with a semicolon. All code lines in Perl must end with the semicolon; the interpreter will complain bitterly if you forget to do this, and its usually the first thing you will do wrong. Be forewarned!
|
![]() |
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. |