in reply to Format multiline to single line records

A simple approach is to loop through the lines and start a new record each time a primary key is detected:
my %record; my $item; while (my $line = <DATA>) { chomp $line; if ($line =~ /^(\d+) (.*)$/) { $item = $1; $record{ $item} = " $2"; } else { $record{ $item} .= $line; } } foreach my $item (keys %record) { print "$item $record{ $item}\n"; } __DATA__ 1000001 01.11.199600.00.00001 A1 1 SN Y 2001.11.200400098.0500073.5500083.35 5001.11.1997Professional attendance being an attendance at 5001.11.1997other than consulting rooms 1000002 01.11.199600.00.00001 A1 1 SN Y 2001.11.200400098.0500073.5500083.35 5001.11.1997Professional attendance being an attendance at 5001.11.1997consulting rooms

-Mark

Replies are listed 'Best First'.
Re^2: Format multiline to single line records
by kerrya (Novice) on Oct 19, 2004 at 22:08 UTC
    Thanks Mark.