pugsly62 has asked for the wisdom of the Perl Monks concerning the following question:
Hi! is there a regular expression I can use instead of my line of code 'if ( $county eq 26005 )' ?
Also, for lines that match '$county eq 26005' I need to count/total the corresponding '$yr_tot' field on the same line. How do you total a $scalar column in perl? there doesn't appear to be a function similar to sql's 'count'.
Thanks!
Scott
use strict; use warnings; my $file = 'scott.d3'; my $FhIn; open $FhIn, '<', $file or die "Could not open $file: $!"; while( my $line = <$FhIn> ) { my ($county, $year, $yr_tot) = split ' ', $line; if ( $county eq 26005 ) { print "$county : $yr_tot\n"; } } close $FhIn or die $!;
20050201 Janitored by Corion: Added formatting
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: regular expressions
by friedo (Prior) on Feb 01, 2005 at 18:12 UTC | |
|
Re: regular expressions
by si_lence (Deacon) on Feb 01, 2005 at 18:14 UTC | |
|
Re: regular expressions
by Tanktalus (Canon) on Feb 01, 2005 at 18:15 UTC | |
|
Re: regular expressions
by holli (Abbot) on Feb 01, 2005 at 18:16 UTC | |
|
Re: regular expressions
by blazar (Canon) on Feb 01, 2005 at 19:36 UTC |