/usr/share/perl5/CGI/examples
NameSizeModeActions
WORLD_WRITABLE/-0755rm
caution.xbm7410644editdlrm
clickable_image.cgi8080644editdlrm
cookie.cgi22630644editdlrm
crash.cgi1310644editdlrm
customize.cgi24540644editdlrm
diff_upload.cgi15950644editdlrm
file_upload.cgi19980644editdlrm
frameset.cgi20760644editdlrm
index.html34870644editdlrm
internal_links.cgi10190644editdlrm
javascript.cgi30490644editdlrm
make_links.pl1960644editdlrm
monty.cgi20860644editdlrm
multiple_forms.cgi15990644editdlrm
nph-clock.cgi3590644editdlrm
nph-multipart.cgi2630644editdlrm
popup.cgi10240644editdlrm
save_state.cgi23110644editdlrm
tryit.cgi7800644editdlrm
Edit: /usr/share/perl5/CGI/examples/cookie.cgi (2263B)
#!/usr/local/bin/perl use CGI qw(:standard); @ANIMALS=sort qw/lion tiger bear pig porcupine ferret zebra gnu ostrich emu moa goat weasel yak chicken sheep hyena dodo lounge-lizard squirrel rat mouse hedgehog racoon baboon kangaroo hippopotamus giraffe/; # Recover the previous animals from the magic cookie. # The cookie has been formatted as an associative array # mapping animal name to the number of animals. %zoo = cookie('animals'); # Recover the new animal(s) from the parameter 'new_animal' @new = param('new_animals'); # If the action is 'add', then add new animals to the zoo. Otherwise # delete them. foreach (@new) { if (param('action') eq 'Add') { $zoo{$_}++; } elsif (param('action') eq 'Delete') { $zoo{$_}-- if $zoo{$_}; delete $zoo{$_} unless $zoo{$_}; } } # Add new animals to old, and put them in a cookie $the_cookie = cookie(-name=>'animals', -value=>\%zoo, -expires=>'+1h'); # Print the header, incorporating the cookie and the expiration date... print header(-cookie=>$the_cookie); # Now we're ready to create our HTML page. print start_html('Animal crackers'); print <Animal Crackers Choose the animals you want to add to the zoo, and click "add". Come back to this page any time within the next hour and the list of animals in the zoo will be resurrected. You can even quit Netscape completely!

Try adding the same animal several times to the list. Does this remind you vaguely of a shopping cart?

This script only works with Netscape browsers

Add/DeleteCurrent Contents EOF ; print "
",start_form; print scrolling_list(-name=>'new_animals', -values=>[@ANIMALS], -multiple=>1, -override=>1, -size=>10),"
"; print submit(-name=>'action',-value=>'Delete'), submit(-name=>'action',-value=>'Add'); print end_form; print "
"; if (%zoo) { # make a table print "
    \n"; foreach (sort keys %zoo) { print "
  • $zoo{$_} $_\n"; } print "
\n"; } else { print "The zoo is empty.\n"; } print "
"; print <
Lincoln D. Stein

More Examples EOF ; print end_html;