Warning.. lengthy email below.. I beg forgiveness in advance :-)
Ok. Here is what I did.
#!/usr/bin/perl
@array1[0..5] = 1; @total[0] = 0;
for($i=0; $i<4; $i++)
{
if($i == 0)
{
@total[$i] = @array1[$i];
print "First group";
print @total[$i];
}
else
{
$j = $i - 1;
print "Second group";
@total[$i] = @total[$j] + @array1[$i];
print @total[$i];
}
}When I run it I get the following:
First group1Second group1Second group1Second group1
So technically it's not even printing the total of your array. The array is fine. Every container is populated with the #1. You are basically printing each container entry in the array. If you are looking for a total of all containers in the @total array you need to add them together in the array. You will need to add them to a scalar variable or a particular container (total[5] perhaps?). Here is what I did. Warning.. not a clean bit of code but it get's the idea across.. I think:
#!/usr/bin/perl
@array1[0..5] = 1; @total[0] = 0;
for($i=0; $i<4; $i++)
{
if($i == 0)
{
@total[$i] = @array1[$i];
print "First group";
print @total[$i];
$total = $total + @total[$i];
print "\n";
print $total;
}
else
{
$j = $i - 1;
print "Second group";
@total[$i] = @total[$j] + @array1[$i];
$total = $total + @total[$i];
print @total[$i];
print "\n";
print $total;
}
}So now you see on the left the sum of each container in the array.
Ok.. I away the flogging. Someone is bound to have done a better job explaining this. At least I can blame it on being up after midnight ;-)
Speaking of which... MERRY CHRISTMAS TO ALL!!!
Night.
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>
