@STATE_LOOKUP = ( undef, # There's no state 0 'Maine', 'Hawaii', 'Canada', 'New York', ... ); my $data; open(FILE, ...) or die(...); while (defined($line = <FILE>)) { my ($state_id, $date) = get_fields($line); my $date_n = convert_date_to_number($date); $data->[$state_id]->{$date}++; } close(FILE); { # Sample output. my ($state_id, $date_n); for ($state_id=1; $state_id<=50; $state_id++) { my $state = $STATE_LOOKUP[$state_id]; foreach $date_n (sort { $a <=> $b } keys %{$data->[$state]}) { my $date = convert_date_to_string($date_n); my $num_tornadoes = $data->[$state]{$date_n}; printf("State %s had %d tornado(es) on %s\n", $state, $num_tornadoes, $date, ) if $num_tornadoes; } } }
get_fields depends on the format of your data.
Look into the Time modules for help implementing convert_date_to_number.
Others will probably use a hash for states without thinking, but an array would be more efficient and just as powerful (assuming you have reports for many states).
In reply to Re: Help with calculating stats from a flat-file database
by ikegami
in thread Help with calculating stats from a flat-file database
by nadocane
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |