#! /usr/bin/perl -w use strict; use Storable qw/freeze thaw/; use CGI ':standard'; my $source; my $destination; my $oldtotal; my $miles; my $date; my $tripdate; my $tripcounter; my $tablesize; my @table; #master array to carry data from previous iterations #my @newdata; #new array to push array-style data into @table #my @tablereform; #new array to take care of spaces in items in @table #my %spaghetti; #to remind myself that my code is horribly convoluted #my %sauce; #to keep spaghetti company #my $i; #for the "for" loop that creates the table my $e; #for the "for" loop that controls the number of elements in @table my $m; #new variable to play with in @table assignments my $n; #ditto as $m my $cookiedata; #outgoing formatted table data comma delimited my $cookiepickup; #incoming cookie data # Now we get our info from the HTML parameters $source = param('source'); $destination = param('destination'); $oldtotal = param('oldtotal'); $tripdate = param('tripdate'); $tripcounter = param('tripcounter'); $cookiepickup = cookie('trip_history'); ********************************************* @table = @{ thaw $cookiepickup }; #this is the problem. ********************************************* # Now we set some controller variables $tablesize = 1; $e = 1; $m = -1; $n = $tripcounter; # Here is the distance database. Can I do this better? if ($source eq 'HHS') { if ($destination eq 'District') { $miles = 6.7} if ($destination eq 'GHS') { $miles = 5} if ($destination eq 'MHS') { $miles = 8.3} } if ($source eq 'GHS') { if ($destination eq 'HHS') { $miles = 5} if ($destination eq 'District') { $miles = 1.7} if ($destination eq 'MHS') { $miles = 3.3} } if ($source eq 'MHS') { if ($destination eq 'District') { $miles = 1.6} if ($destination eq 'GHS') { $miles = 3.3} if ($destination eq 'HHS') { $miles = 8.3} } if ($source eq 'District') { if ($destination eq 'MHS') { $miles = 1.6} if ($destination eq 'GHS') { $miles = 1.7} if ($destination eq 'HHS') { $miles = 6.7} } if ($source ne $destination) { $oldtotal = $miles + $oldtotal; $tripcounter = $tripcounter + 1; push (@table, $tripdate, $source, $destination, $miles); $cookiedata = freeze \@table; # push(@table, @newdata); print qq (Set-cookie:trip_history=$cookiedata \n); print qq (Content-type: text/html\n\n Mileage); print qq (
); print qq (Trip Number $tripcounter ----------); print qq (Trip Date:
); print qq (Starting Point:); print qq (Ending Point:); print qq (

); print qq (Current mileage is miles
); print qq (
); # Retrieve Date &get_date; sub get_date { my @days; my @months; my $sec; my $min; my $hour; my $mday; my $mon; my $year; my $wday; my $time; # Define arrays for the day of the week and month of the year. @days = ('Sunday','Monday','Tuesday','Wednesday', 'Thursday','Friday','Saturday'); @months = ('January','February','March','April','May','June','July', 'August','September','October','November','December'); # Get the current time and format the hour, minutes and seconds. Add # 1900 to the year to get the full 4 digit year. ($sec,$min,$hour,$mday,$mon,$year,$wday) = (localtime(time))[0,1,2,3,4,5,6]; $time = sprintf("%02d:%02d:%02d",$hour,$min,$sec); $year += 1900; # Format the date. $date = "$days[$wday], $months[$mon] $mday, $year"; } print qq (


$date); print qq (); print qq (
cookie value is @table); }