The Contents of the Shopping Cart
The cart.pl file is used to view the contents of shopping carts, and to allow users to remove items from the cart if they no longer intend to purchase them. If the script receives no parameters, it just retrieves the list of items in the user’s shopping cart and displays them. Each item in the cart is accompanied by a form that can be used to remove that item from the shopping cart. If the action parameter is set to remove,it attempts to remove the specified item from the cart. The full source code for the script appears in Listing 16.3.
Listing 16.3. The Source Code for cart.pl
1: #!/usr/local/bin/perl 2: 3: use strict; 4: 5: use CGI; 6: use CGI::Carp qw( fatalsToBrowser ); 7: 8: my $cart_file = "cart.txt"; ... |
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.