On Wed, 20 Oct 2004 22:27:20 -0400, Kevin Old <[EMAIL PROTECTED]> wrote:
> Hello everyone,
> 
> I have several "sections" of data that look like this:
> 
> 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
> 
> 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.
> 
> Any ideas how I'd do this?
> 

Here is a suggestion:


# Use blank lines (not newlines) to separate input records
$/="";

# Read the input data (<DATA> is the __DATA__ section at the end of the file)
while( $_ = <DATA> ) {
        # clean the input
        chomp$_;

        # Display input for comparison
        print "Parsing : ".join("\n          ",split(/\n/,$_))."\n\n";

        # Convert input data into a hash
        $rec{$1}=$2 while /^(.*?): (.*)$/mg;

        # output data record..
        for( keys %rec ) {
                printf "%13s: [%s]\n",$_,$rec{$_};
        }
        #separate records in output
        print "\n"
}

# Dummy input data below.
__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 \026 Max V Armchair

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 \026 Max V Armchair

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 \026 Max V Armchair

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 \026 Max V Armchair



HTH. Cheers.


> Thanks,
> Kevin
> --
> Kevin Old
> [EMAIL PROTECTED]
> 
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
> 
>

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to