Hello everyone,
Sorry for the spam, I am new to Perl and am having a hard time manipulating arrays. Below is the sample code that I am working on:
@array1[0..5] = 1; @total[0] = 0;
for($i=0; $i<4; $i++) { if($i == 0) { @total[$i] = @array1[$i]; print @total[$i]; } else { $j = $i - 1; @total[$i] = @total[$j] + @array1[$i]; print @total[$i]; } }
This code would work in C/C++, but with Perl, instead of adding up the previous values, the array "Total" seems to treat the integer value as a string and join them together. So instead of ending up with 4 as my resulting total, I instead get 1111. I know this is a rather dumb question, but any help would be GREATLY appreciated. Thanks in advance.
hint #1: Add the following to the beginning of your program
use strict; use warnings;
hint #2: Do you know the difference between '@total[$i]' and '$total[$i]' ?
Randy.
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>