#! /usr/bin/perl
use strict;
use warnings;
my %data;
my @columns;
my $current;
my $line;
while (<DATA>)
{
chomp;
$line = $_;
if ($line =~ /:$/)
{
push @columns, $line;
$current = $line;
$data{$current} = ();
}
else
{
push @{$data{$current}}, $line;
}
}
print join (",", @columns), "\n";
my $count = @{$data{$columns[0]}};
for my $i (0 .. $count - 1)
{
for my $c (0 .. $#columns)
{
print $data{$columns[$c]}[$i];
print "," if $c < $#columns;
}
print "\n";
}
__DATA__
heading1:
text1
text2
text3
heading2:
text1
text2
text3
Output is:
heading1:,heading2:
text1,text1
text2,text2
pbeckingham - typist, perishable vertebrate.