I'm trying to create a CSV file from the text data below.  Lines
containing High and Low Tide data have 9 fields, lines having
sunrise/sunset and lunar data have 8 fields.

How you differentiate between the two conditions?

2000-12-03 11:30 AM PST   9.39 feet  High Tide
2000-12-03  4:15 PM PST   Sunset
2000-12-03  7:56 PM PST   First Quarter
2000-12-04  3:42 AM PST   2.81 feet  Low Tide
2000-12-04  7:48 AM PST   Sunrise

<--------->

while (<INFILE>) {

    ($year, $month, $mday, $hour, $minute, $am_pm, $tz, $height, $cond)
=
    ^(\d+)-(\d+)-(\d+)\s+(\d+):(\d+)\s+([A-Z]{2})\s+([A-Z]{3})\s+
    ([0-9A-Za-z-.\s]{11})\s+(\w+\s+\w+)/;

    $year and $started++;

    if ($cond) {
    ($year, $month, $mday, $hour, $minute, $am_pm, $tz, $cond) =
    /^(\d+)-(\d+)-(\d+)\s+(\d+):(\d+)\s+([A-Z]{2})\s+([A-Z]{3})\s+
    ([A-Za-z\s])/;

    $date = "$year-$month-$mday";
    $time = "$hour:$minute";
    # Strip the leading and trailing spaces from $height
    StripLTSpace($height);
                
    printf OUTFILE "%s\,%s\,%s\,%s\,%s\,%s\n",
        $date, $time, $am_pm, $tz, $height, $cond;
    }
            
}       

$started or print STDERR "Didn't find a tides line";
        
close(INFILE);
close(OUTFILE);
print STDERR "\n";

1;

Reply via email to