in reply to Stupid loops, or is it just me?
Ugh. Why are you working with single values? split returns a list.($var1) = (split(/\s+/, $strip))[0]; ($var2) = (split(/\s+/, $strip))[1]; ($var3) = (split(/\s+/, $strip))[2]; $line[0] = $var1; $line[1] = $var2; $line[2] = $var3;
When you say@line = split(/\s+/, $strip);
the commas should be semicolons. Also, since all you want to do is iterate over indices 0 to 146, just say so:for ($i=0,$i<147,$i++)
Much easier to read, no? And finally - Perl understands lists. Why use indices where you don't need to? That's rarely necessary and often a source of errors. Instead offor my $i (0 .. 146)
it is better to sayfor ($j=0,$j<360,$j++) { $decavg2d[$i][$j] += $decavg[$i]; print "$decavg2d[$i][$j]\n"; }
for my $i (0 .. 146) { for (@decavg2d[$i][0 .. 359]) { $_ += $decavg[$i]; print "$_\n"; } }
Recommended reading: Mark-Jason Dominus' excellent Program Repair Shop and Red Flags article series on Perl.com.
Lastly - please get into the habit of using strict and warnings. It will save you a lot of headaches.
Makeshifts last the longest.
|
|---|