Hi.
Im defining a variable in a foreach() loop. It calculates a total, based on values retrieved from a textfile.
I want to store this variable called $grandTotal, in a cookie.
The problem i'm having is that I cannot define a cookie after the "Content-type=text/html\n\n" line. I've tried defining the cookie at the start, but it just gives me the value 0 as there is no value assigned to it yet.
Is there anyway i can update the variable at the top, with the result I have from the loop.
The code is below.
I want the value of $grandTotal from the loop, to update the value of $grandTotal at the top of the page.Code:#!/usr/bin/perl use CGI::Carp qw(fatalsToBrowser); $grandTotal = 0; $file = "DONATIONS.TXT"; # Locate the file open(HANDLE, $file) || die("Could not open the file."); # Open the file @data=<HANDLE>; # Add handler to an array close(HANDLE); # Close file handler print "Set-Cookie:totalDon=$grandTotal;"; print "Content-type=text/html\n\n"; print <<HTMLCODE; <font face='verdana'> <TABLE border=1> <TR> <TD><b>Display Name</TD> <TD><b>Date</TD> <TD><b>Comments</TD> <TD><b>Tax Bonus</TD> <TD><b>Amount</TD> </TR> HTMLCODE foreach $donation(@data) { chomp($donation); ($name, $date, $total, $tax, $comment)=split(/\|/, $donation); # Split file where there is a pipe print "<TR>"; print "<TD>$name</TD>"; print "<TD>$date</TD>"; print "<TD>$comment</TD>"; print "<TD>$tax</TD>"; print "<TD>$total</TD>"; $grandTotal = $grandTotal + $total; }
Thanks!





Bookmarks