Below is snipit of code that is intended to read in the station_id
from the header of each example file. In each case the reg expression
is supposed to find the 6 digit number within the parentheses. Both
files contain 6 lines in the header. For some reason the reg
expression will not catch the station_id in the 2nd example. Oddly
however, if I paste the data portion of the first file, into the 2nd
file, then the the reg expression catches the station id in the 2nd
example. Any ideas?
my $station_id = '';
while ( <> ) {
#Part 1. Loop through the header lines to identify the station id.
#The station ID has the format of:
#STATION: (SOME_STATION_ABVR) SOME_STATION_NAME_AP (Station ID:
######)
if ( 1 .. 6 ) {
$station_id = $1 if /\(Station ID:\s*(\S+)\)/;
next;
}
#At eof close the input filehandle to reset $.
if ( eof || !/\S/) {
close ARGV;
next;
}
print $station_id; }
======================================
EXAMPLE 1
======================================
STATION: WIND_POINT, WI (Station ID: 479983)
Precip- Snow Snow Obser-
itation Low High Fall Depth Mean vation Data
Year Mo Dy (in) (F) (F) (in) (in) (F) Time Source
2003 01 01 M M M M M M - -
2003 01 02 M M M M M M - -
2003 01 03 M M M M M M - -
2003 01 04 M M M M M M - -
2003 01 05 M M M M M M - -
=======================================
EXAMPLE 2
=======================================
Station: (APN) ALPENA_WSO_AP (Station ID: 000024)
yyyymmdd Air WetB DewP Min Max Wind Wind SeaLev Solar Pot
Temp Temp Temp RelH RelH Speed Direc Press Radiat Evap
(F) (F) (F) (per) (per) (mph) (deg) (mb) (MJ/sq m) (in)
19900102 0m 0m 0m 0m 0m 0m 0m 0m 0m 0m
19900103 0m 0m 0m 0m 0m 0m 0m 0m 0m 0m
19900104 0m 0m 0m 0m 0m 0m 0m 0m 0m 0m
19900105 0m 0m 0m 0m 0m 0m 0m 0m 0m 0m
19900106 0m 0m 0m 0m 0m 0m 0m 0m 0m 0m
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/