in reply to Average calculation

What does your existing code look like? It could be that your implementation, using a hash (which seems entirely reasonable) is almost on the mark. Wouldn't it be of more value to you for us to help figure out what you're doing wrong, rather than having us provide you a cut-and-paste solution?

Here's how I would do it: Create a hash. Then iterate over each line of the file. chomp each line (to get rid of the \n). split on the ':' character. Retain the first element (state) and the third element (temperature). push each temperature into an anonymous array held as the value of the hash element indexed by the state: push @{$states{$state}}, $temp;. Then open your output file. Iterate over each state in the hash. Calculate the average by summing all elements for a given state, and then dividing by the number of elements. Save to your output file the state name and the average temperature. close your output file. Be sure to check return values on filesystem calls such as open and close.


Dave