Code Comments
Programming Forum and web based access to our favorite programming groups.
Begin forwarded message:
On Aug 23, 2007, at 4:25 PM, Mr. Shawn H. Corey wrote:
> # How about?
> my ( $year, $month, $doy, $tmax, $tmin, $par, $precip, $NH4, $NO3,
> $O3, $CO2, $V1, $V2, $V3, $V4 ) = split;
> # You can now store your totals by month as:
> $totals{$year}{$month}{tmax} += $tmax;
> ...
> # and the count
> $totals{$year}{$month}{count} ++;
>
> # After you read all the input, you can calculate the averages.
>
Interesting idea. I like it in that it is flexable (for example I
could easily print the monthly sum of precip by not dividing by a
"count", which brings me to my question. I see how you are summing
each of the variables like tmax with:
+= $tmax;
I'm not sure though how you are keeping track of the "count". In
order to print out averages, I'd have to do something like:
print $year, $doy / count, $tmax / count, $tmin / count
I don't see how $totals{$year}{$month}{count} ++; is holding the count.
Post Follow-up to this messageKirk Wythers wrote:
> I don't see how $totals{$year}{$month}{count} ++; is holding the count.
Read about the auto-increment operator in "perldoc perlop".
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.