The Catalog Script

Now that you’ve got a picture of what the relational database looks like, let’s examine the modified catalog.pl program. This program offers the same functionality as the catalog program from Hour 16. It displays the catalogs for users, and process requests to add items to the user’s shopping cart. It differs from the old script in that it opens a database connection instead of creating filehandles, and processes the results of SQL queries instead of parsing files. The source code for the new catalog.pl program appears in Listing 20.3.

Listing 20.3. The Source Code for catalog.pl
 1: #!/usr/local/bin/perl 2: 3: use strict; 4: 5: use CGI; 6: use CGI::Carp qw( fatalsToBrowser ); 7: use DBI; 8: 9: my $query = new CGI; 10: 11: ...

Get Sams Teach Yourself CGI in 24 Hours, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.