Make sure each section is separated by a new line, including the last
section. If there is no new line at the end of the file, the last record
will be omitted.
The following puts each field in %data with the field name being the key and
the field value as the key's value, and it splits each line on the FIRST
colon:
----------------------------
#!/usr/bin/perl
use warnings;
use strict;
# connect to your db here
$/ = '';
while (<DATA>) {
my %data = map { split /\s*:\s*/, $_, 2 } split /\n/;
# instead of printing here, you would write to your database using the
connection from above
print "$_ ==> $data{$_}\n" foreach sort keys %data;
}
__DATA__
Title: DESIGN JOURNAL (COVER)
Purpose: Product Spotlight
Penetration: National
Role: Media Relations, Content Support
Results: Elevated Publicity and Brand Awareness
Credits: Evolutif Senior Management Team
Award: 2001 Award for Design Excellence - Max V Armchair
----------------------------
"Kevin Old" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
Hello everyone,
I have several "sections" of data that look like this:
<snip>
Each "section" is separated by an empty line. I'd like to capture one
"section" at a time, and then when each section has been captured, I'd
like to write it to a database. I just can't figure out how to
identify the end of the section.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>