Trying to get it to print out what is going into the @decavg array gets me only 9 zeros, which is neither what I want, nor the 147 iterations I expect. Every time I have had the program print up until that point I have gotten some kind of output, but there it fails. This next part is where I have failed time and again. I set up a nested for loop that should assign, for all the vertical degrees, the calculated average value to every horizontal step.#!/usr/bin/perl -w use FileHandle; $fh = new FileHandle "/data/jkerwin/muskyoutput/ravsdec.dat"; die "Can't open RAvsDEC file" unless (defined($fh)); @decavg = (); $i=0; $j=0; @line=(); for ($i=0,$i<147,$i++) { $decavg[$i] = 0; } while (defined($strip = <$fh>)) { ($var1) = (split(/\s+/, $strip))[0]; ($var2) = (split(/\s+/, $strip))[1]; ($var3) = (split(/\s+/, $strip))[2]; $line[0] = $var1; $line[1] = $var2; $line[2] = $var3; $decavg[$line[0]] += $line[2]; } for ($i=0,$i<147,$i++) { $decavg[$i] = $decavg[$i]/360; print "$decavg[$i]\n"; }
Again, when I try to print this out I get a small number of zeroes. Why won't this print out something meaningful? Do I need to use a hash array instead? (I tried, and it gave me the same kind of error). Thanks in advance for any help you can offer me. - jason "newbie" kerwin@decavg2d = (); for ($i=0,$i<147,$i++) { for ($j=0,$j<360,$j++) { $decavg2d[$i][$j] = 0; } } for ($i=0,$i<147,$i++) { for ($j=0,$j<360,$j++) { $decavg2d[$i][$j] += $decavg[$i]; print "$decavg2d[$i][$j]\n"; } }
In reply to Stupid loops, or is it just me? by jkerwin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |