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.
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
($name, $date, $total, $tax, $comment)=split(/\|/, $donation); # Split file where there is a pipe
$grandTotal = $grandTotal + $total;