On Wed, May 27, 2009 at 11:30, Kirk Wythers <[email protected]> wrote:
> I have a large datafile that I am trying to read into a postgresql database.
> I think I have the db_connect stuff down, but I'm fighting with the part
> that reads the file to be processed. The file contains a repeating structure
> of header lines like this:
>
> TOA5 B4WARM_C CR1000 16474 CR1000.Std.15
> TIMESTAMP RECORD Flag(1) Flag(2) Flag(3)
> TS RN
> Smp Smp Smp
> 4/29/09 15:10 0 0 0 0
> 4/29/09 15:11 1 0 0 0
> 4/29/09 15:12 2 0 0 0
> 4/29/09 15:13 3 0 0 0
> 4/29/09 15:14 4 0 0 0
> 4/29/09 15:15 5 0 0 0
> 4/29/09 15:16 6 0 0 0
> 4/29/09 15:17 7 0 0 0
> 4/29/09 15:18 8 -1 -1 -1
> 4/29/09 15:19 9 -1 -1 -1
> 4/29/09 15:20 10 -1 -1 -1
> TOA5 B4WARM_C CR1000 16474 CR1000.Std.15
> TIMESTAMP RECORD Flag(1) Flag(2) Flag(3)
> TS RN
> Smp Smp Smp
> 4/29/09 15:10 0 0 0 0
> 4/29/09 15:11 1 0 0 0
> 4/29/09 15:12 2 0 0 0
> 4/29/09 15:13 3 0 0 0
> 4/29/09 15:14 4 0 0 0
> 4/29/09 15:15 5 0 0 0
> 4/29/09 15:16 6 0 0 0
> 4/29/09 15:17 7 0 0 0
> 4/29/09 15:18 8 -1 -1 -1
> 4/29/09 15:19 9 -1 -1 -1
> 4/29/09 15:20 10 -1 -1 -1
>
>
> I want to read in the lines that begin with the date format, but skip all
> the header stuff. Can anyone suggest a strategy for a, "if the line begins
> with XXXX, go ahead and read".
>
> Thanks in advance.
while (<>) {
next unless my ($date, $time, $sample, @flags) = m{
^
(..?/..?/..)
(..:..)
([0-9]+) \s+
([0-9]+) \s+
([0-9]+) \s+
([0-9]+) \s+
$
}x;
}
--
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.