in reply to regular expressions
The question isn't entirely clear ... but here's my inferrence.
First, use "==" rather than "eq" when comparing numbers. Of course, you may actually be comparing strings - but then put the string in quotes. For example, if "26005.0000" is the same as "26005", then use ==. If they're different, use eq, but put "26005" in quotes (single or double, doesn't matter).
(also, please don't put all those spaces at the end of the lines .. they're just distracting ;->)
use strict; use warnings; my $file = 'scott.d3'; my $FhIn; open $FhIn, '<', $file or die "Could not open $file: $!"; my $total; while( my $line = <$FhIn> ) { my ($county, $year, $yr_tot) = split ' ', $line; if ( $county == 26005 ) { # - or - # if ( $county eq '26005' ) { print "$county : $yr_tot\n"; $total += $yr_tot; } } close $FhIn or die $!; print "Total yr_tot's: $total\n";
|
|---|