![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Perl CGl Programming: No experience required.
You need to change the guts of the search next. Its actually quite simple to turn your previous test for string equality into two regular expressions linked with the logical AND operator: # Check the fields for a match; display the entire # entry if it matches, or get another if not. if (($InfoArray[$LastName] =~ /$SearchTerms[0]/) && ($InfoArray[$FirstName] =~ /$SearchTerms[1]/)) { print <<ALLDONE; Because of the && linking the two regular expressions, the test can only succeed if both statements are true. If either of the form fields was left blank, the value of $SearchTerms[] in the regular expression will match anything, so that part of the test will always be true.
Finally, the new search.pl needs a change at the bottom, where a message is displayed if the search fails entirely. # If the $Found flag is still 0, put up a message. if (!$Found) { print "<H2 ALIGN=\"CENTER\">Sorry. No matches found for "; print "$SearchTerms[0] $SearchTerms[1]</H2>\n"; } # End search.pl As you can see, this conditional expression only prints both search terms in the message if the $Found flag is set to false. Now, invoke search.html from your Web browser, fill out the form and submit it. From the example given in Figure 12.5, the result looks like the page in Figure 12.6.
Programming for the InternetNetwork programming is an art that is both arcane and frustrating, but it has its rewards, too. If your program can get out to the network, youve left the bounds of your own computer. If the network is connected to the Internetitself nothing but a worldwide networkthen your program knows no bounds. Perl contains a rich set of TCP/IP networking functions, all of which were copied directly from the C-language sockets library. This library of networking tools was originally developed in the early 1980s as part of what now is known as BSD (or simply Berkeley) UNIX, with BSD standing for Berkeley Systems Development. The BSD project started as a semi-covert hack of the original AT&T Bell Labs UNIX kernel undertaken by a ragtag group of graduate students in computer science at the University of California. Many members of this group, which included the likes of Ken Arnold and Bill Joy, went on to become demigods in the UNIX worldlegends of programming, as it were. So its not surprising that BSD UNIX became one of the two standard flavors of UNIX, along with AT&Ts System V. Most of the modern UNIX versions have incorporated the best aspects of System V and BSD.
Because networking hadnt become quite the rage in the early 80s that it is now, AT&Ts UNIX had no standard library of network functions. It was considered to be a task that should be tackled at the device-driver level; in other words, you had to roll your own networking tools. Our precocious group of Berkeley grad students disagreed with this philosophy. At first, they attempted to shoehorn networking functions into the universal UNIX canon of input and output: Everything is a file. In UNIX, virtually anything that can be read or written to, including peripheral devices such as printers and serial ports, is addressed through standard file operations. You open it, you read from it or write to it, you close it. But the BSD group found that networking was too complex to fit into the neat package of file maintenance, so they developed the philosophy, and then the library, called sockets. The idea is similar to the traditional concepts of file I/O with a subtle twist. A socket is something that you plug into, rather than open as you would a book or a file cabinet. Once the connection is made, the established operations of reading and writing come into play for input and output; its that initial connection thats important and its the reason the Berkeley group had to develop a separate library of functions for networking.
|
![]() |
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. |