in reply to Editing a text file

I disagree with diotalevi: not all "interesting lines" start with a dot. I can see that those lines can be wrapped. An example of the file I just downloaded using wget:
.WEDNESDAY...MOSTLY SUNNY. HIGHS IN THE LOWER 50S. EAST WINDS 5 TO 10 MPH. .WEDNESDAY NIGHT...MOSTLY CLEAR. LOWS IN THE UPPER 20S. EAST WINDS 5 TO 10 MPH. .THANKSGIVING DAY...PARTLY SUNNY. HIGHS IN THE LOWER 50S.
See the wrapping in or around the wind speeds?

I think one easy way to unwrap such a short file, is to first collect the block you want, and then split on the dots that start a line. Something like:

@ARGV = 'paz049.txt'; my $buffer = ''; while(<>) { if(s/^\.// .. /^$/) { $buffer .= $_; } } $buffer =~ s/\s+$//; $buffer =~ s/\n(?!\.)/ /g; my @lines = split /\s*\n\./, $buffer;

If I now print out all the data in @lines, I seem to get the proper result:

TONIGHT...BECOMING PARTLY CLOUDY. LOWS IN THE MID 20S. NORTHWEST WIND +S AROUND 5 MPH. TUESDAY...PARTLY CLOUDY IN THE MORNING...THEN BECOMING SUNNY. HIGHS IN + THE MID 40S. SOUTHWEST WINDS AROUND 5 MPH. TUESDAY NIGHT...CLEAR. LOWS IN THE MID 20S. SOUTH WINDS AROUND 5 MPH. WEDNESDAY...MOSTLY SUNNY. HIGHS IN THE LOWER 50S. EAST WINDS 5 TO 10 M +PH. WEDNESDAY NIGHT...MOSTLY CLEAR. LOWS IN THE UPPER 20S. EAST WINDS 5 TO + 10 MPH. THANKSGIVING DAY...PARTLY SUNNY. HIGHS IN THE LOWER 50S. THURSDAY NIGHT...INCREASING CLOUDS. A 30 PERCENT CHANCE OF SHOWERS. LO +WS IN THE MID 30S. FRIDAY...MOSTLY CLOUDY WITH A 30 PERCENT CHANCE OF SHOWERS. HIGHS IN T +HE LOWER 50S. FRIDAY NIGHT...MOSTLY CLOUDY. LOWS IN THE UPPER 30S. SATURDAY...PARTLY CLOUDY. HIGHS IN THE LOWER 50S. SATURDAY NIGHT...PARTLY CLOUDY. LOWS IN THE LOWER 30S. SUNDAY...PARTLY CLOUDY IN THE MORNING...THEN BECOMING SUNNY. HIGHS ARO +UND 50. SUNDAY NIGHT...PARTLY CLOUDY. LOWS IN THE MID 30S. MONDAY...DECREASING CLOUDS. HIGHS IN THE UPPER 40S.

Replies are listed 'Best First'.
Re^2: Editing a text file
by appletag (Initiate) on Nov 21, 2006 at 01:33 UTC
    Thanks bart, I'm evaluating Geo::WeatherNOAA but I want to learn more about perl. I look forward to trying out this code. BR