pugsly62 has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
Another simple question from a novice. I'm trying to get subtotals for the table below, both by county and by year. Do I have to run subroutines since my code has already used the '$yr_tot' variable to separate by county/year?
Thanks!
Scott
Table example: COUNTY 2001 2002 2003 2004 ------ ------ ------ ------ ------ 26005 432 505 547 555 26021 910 984 1026 1077 26023 225 282 272 299 26025 711 796 809 899 26027 250 319 318 313 26059 196 221 242 292 26077 1170 1371 1439 1439 26149 355 415 346 367 26159 414 434 504 493
Code Example:
my $records = 'scott.d3'; my $FhIn; my $yr_01; my $yr_02; my $yr_03; my $yr_04; my $timestamp = localtime(time()); open $FhIn, '<', $records or die "Could not open $records: $!"; open(FILE, ">report.txt") or die "Can not open file"; while( my $line = <$FhIn> ) { my ( $county, $year_x, $yr_tot ) = split ' ', $line; if ( $year_x eq "1" ) { $yr_01 = $yr_tot; } elsif ( $year_x eq "2" ) { $yr_02 = $yr_tot; } elsif ( $year_x eq "3" ) { $yr_03 = $yr_tot; } elsif ( $year_x eq "4" ) { $yr_04 = $yr_tot; }
20050224 Janitored by Corion: Added formatting
20050224 Edit by castaway: Changed title from 'subtotals'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Calculating subtotals from a table
by sh1tn (Priest) on Feb 24, 2005 at 16:06 UTC | |
|
Re: Calculating subtotals from a table
by artist (Parson) on Feb 24, 2005 at 16:22 UTC | |
|
Re: Calculating subtotals from a table
by Jasper (Chaplain) on Feb 24, 2005 at 18:02 UTC | |
|
Re: Calculating subtotals from a table
by exussum0 (Vicar) on Feb 24, 2005 at 15:27 UTC | |
|
Re: Calculating subtotals from a table
by Anonymous Monk on Feb 24, 2005 at 16:24 UTC |