Take two bites at the cherry. First extract the (possibly null) string between the first and last record and then extract the coordinates from that:
#! perl -slw
use strict;
local $/ = ''; ## paragraph mode
while( <DATA> ) {
print "\n'$_' contains";
if( my( $coords ) = m[MAX.*?\n(.*)\nREPEAT]s ) {
my @coords = $coords =~ m[((?:\d+(?:NW|N|NE|E|SE|S|SW|W)[ .]+)
+{4})]g;
print "\t$_" for @coords;
}
else {
print 'No coords';
}
}
__DATA__
MAX SUSTAINED WINDS 65 KT WITH GUSTS TO 80 KT.
REPEAT...CENTER LOCATED NEAR 17.0N 77.5W AT 11/2100Z
MAX SUSTAINED WINDS 65 KT WITH GUSTS TO 80 KT.
64 KT....... 25NE 0SE 0SW 25NW.
REPEAT...CENTER LOCATED NEAR 17.0N 77.5W AT 11/2100Z
MAX SUSTAINED WINDS 65 KT WITH GUSTS TO 80 KT.
64 KT....... 25NE 0SE 0SW 25NW.
50 KT....... 40NE 0SE 0SW 40NW.
34 KT.......100NE 75SE 0SW 75NW.
12 FT SEAS..175NE 100SE 50SW 175NW.
REPEAT...CENTER LOCATED NEAR 17.0N 77.5W AT 11/2100Z
Produces:
P:\test>420431
'MAX SUSTAINED WINDS 65 KT WITH GUSTS TO 80 KT.
REPEAT...CENTER LOCATED NEAR 17.0N 77.5W AT 11/2100Z
' contains
No coords
'MAX SUSTAINED WINDS 65 KT WITH GUSTS TO 80 KT.
64 KT....... 25NE 0SE 0SW 25NW.
REPEAT...CENTER LOCATED NEAR 17.0N 77.5W AT 11/2100Z
' contains
25NE 0SE 0SW 25NW.
'MAX SUSTAINED WINDS 65 KT WITH GUSTS TO 80 KT.
64 KT....... 25NE 0SE 0SW 25NW.
50 KT....... 40NE 0SE 0SW 40NW.
34 KT.......100NE 75SE 0SW 75NW.
12 FT SEAS..175NE 100SE 50SW 175NW.
REPEAT...CENTER LOCATED NEAR 17.0N 77.5W AT 11/2100Z
' contains
25NE 0SE 0SW 25NW.
40NE 0SE 0SW 40NW.
100NE 75SE 0SW 75NW.
175NE 100SE 50SW 175NW.
Examine what is said, not who speaks.
Silence betokens consent.
Love the truth but pardon error.
|