#! /usr/bin/perl

#   Copyright (c) 2003,6 Martin Schulze <joey@infodrom.org>
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; version 2 dated June, 1991.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program;  if not, write to the Free Software
#   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.

use strict;
use warnings;

use Text::CSV;

my $csv = Text::CSV->new({binary => 1, sep_char => ';'});

open (my $io, $ARGV[0]) || die "Can't open " . $ARGV[0];

my @data;
while (my $columns = $csv->getline ($io)) {
    push @data, $columns;
}
close $io;

my $pivot = '';
my $line = '';
foreach (sort {$a->[0] cmp $b->[0]} @data) {
    if ($pivot ne $_->[0]) {
	printf '"%s";"%s"'."\n", $pivot, $line if length $pivot;
	$line = '';
    }
    $pivot = $_->[0];
    $line .= ' ' if length $line;
    $line .= $_->[1];

    # printf "%s\n", $_->[0];
}

printf "%s: %s\n", $pivot, $line if length $pivot;

