#!/usr/bin/perl -w
#---------#---------#---------#---------#---------#---------#---------#---------
# Title
#   convert multiline records to comma seperated value records
# Author
#   Andrew Johnson  http://members.home.net/perl-epwp/
# Description:
# One common type of multi-line record is the name/value pair format.
# In this case, we have records consisting of three named fields
# separated by "*****\n". We can simply read this data in and output it
# as a csv file with a ':' as the field separator and ordered fields:
#    name, age, beer.
#---------#---------#---------#---------#---------#---------#---------#---------
    # set the input record separator to this string.
    $/ = "*****\n";

    my @fields = qw/name age beer/;
    while(<DATA>){
        # chomp() removes any trailing record separator,
        # not just any trailing newline character
        chomp;
        # create a hash by splitting the record at every '=' and "\n" character
        # account for possible whitespace around the '=' character
        my @data = split /\s*[\n=]\s*/;
        # strip any leading spaces
        s/^\s+// for @data;

        my %hash = @data;
        print join(':',@hash{@fields}),"\n";
    }

__DATA__
    name = andrew
age = 37
beer = dark ale
*****
name = john
  beer = pale ale
age = 35
*****

