bazz
09-17-2009, 06:04 AM
Hi,
I have built a hash as shown below. I did this because within a while loop, I couldn't seem to make the outputted sub_totals, add on each iteration without only getting the total of the last loop.
anyhow, even when looping through the while loop for the hash, I can't add up the values correctly.
'subs' => {
'97' => {
'90.00' => 1,
'76.50' => 1,
'90.90' => 1
}
},
my $room_total=0;
my $sub_total=0;
while (my ($tariff, $sub_total) = each %room_total) {
$room_total = ($sub_total + $sub_total);
}
$room_total = sprintf("%.2f", $room_total );
print qq( <tr><td>total=$room_total</td></tr> );
that hash is totalled as 350533824.00 :eek:
I think the way a while loop runs, being different from a foreach, is making me confuse myself.
any pointers very welcome
oh, just thought; maybe I should process the hash with a foreach loop?
bazz
I have built a hash as shown below. I did this because within a while loop, I couldn't seem to make the outputted sub_totals, add on each iteration without only getting the total of the last loop.
anyhow, even when looping through the while loop for the hash, I can't add up the values correctly.
'subs' => {
'97' => {
'90.00' => 1,
'76.50' => 1,
'90.90' => 1
}
},
my $room_total=0;
my $sub_total=0;
while (my ($tariff, $sub_total) = each %room_total) {
$room_total = ($sub_total + $sub_total);
}
$room_total = sprintf("%.2f", $room_total );
print qq( <tr><td>total=$room_total</td></tr> );
that hash is totalled as 350533824.00 :eek:
I think the way a while loop runs, being different from a foreach, is making me confuse myself.
any pointers very welcome
oh, just thought; maybe I should process the hash with a foreach loop?
bazz