winesearch.pl

#!D:\Perl\bin\perl.exe 
use CGI qw(:standard); 
use CGI::Cookie;
#         winesearch.pl 
# 
# Sample code used to generate a wine search. Note that it 
# does not actually conduct any sort of search. It just 
# enters the search into the user's preferences. 
# 
# The search itself is conducted by the realsearch.pl 
# script.
srand;
%cookies = fetch CGI::Cookie;
if ($cookies{'findagoodwineID'} ) { 
    $myID = $cookies{'findagoodwineID'}->value; 
} else { 
    $myID = getrandomID(); 
}
# We create the cookie, with a name, ID, and expires time 
# of 10 years.
$winecookie = new CGI::Cookie(-name=>'findagoodwineID',
    -value=>$myID,-expires=>'+10y');
# We get the query string and append it on to the 
# _real_ cgi-bin script
$searchURL = '/cgi-bin/findagoodwine/realsearch.pl?'. 
    $ENV{'QUERY_STRING'};
# and we get the time and use that as our search 
# description
$searchDesc = "Search submitted ". localtime(); 
$bigstring = $searchURL. '~::~'. $searchDesc;
dbmopen(%history, "winehistory", 0644) || die "cannot open DBM $!";
@lastsearch = split(/~:~/, $history{$myID});
$lastsearch[2] = $lastsearch[1]; 
$lastsearch[1] = $lastsearch[0]; 
$lastsearch[0] = $bigstring;
$finallist = join("~:~", @lastsearch);
$history{$myID} = $finallist;
dbmclose(%history);
print "Content-type: text/html\n"; 
print "Set-Cookie: $winecookie\n"; 
print "Cache-Control: private\n";
print <<"End_of_Page";
<HTML> 
    <HEAD> 
    <META name="HandheldFriendly" content="True"> 
    <TITLE>Search has been entered</TITLE> 
    </head> 
    <BODY>
    Thanks for your search. Go back and reload the 
    <a href="/cgi-bin/findagoodwine/frontpage.pl">Front page</a> 
    to see the results of your new search.
    <p> 
    More debug info: 
    <p>
    searchURL = $searchURL <br> 
    searchDesc = $searchDesc <br> 
    lastsearch2 = $lastsearch[2] <br> 
    lastsearch1 = $lastsearch[1] <br> 
    lastsearch0 = $lastsearch[0] <br> 
    <p> 
    finallist = $finallist 
    </body>
</html>
End_of_Page
sub getrandomID { 
    return (time(). sprintf("%07d",(int(rand(5000000))))); 
}
# 
# Copyright (c) 2007, iAnywhere Solutions, Inc., 
# all rights reserved. 
# 
# IANYWHERE MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT 
# THE SUITABILITY OF THE SOFTWARE, EITHER EXPRESS OR 
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED 
# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 
# PURPOSE, OR NON-INFRINGEMENT. IANYWHERE SHALL NOT BE 
# LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT 
# OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR 
# ITS DERIVATIVES.