For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > August 2007 > Fwd: aggregating time steps









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Fwd: aggregating time steps
Kirk Wythers

2007-08-24, 4:00 am



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.


Gunnar Hjalmarsson

2007-08-24, 4:01 am

Kirk 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
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com