in reply to Extracting fields
while (<DATA>) { chomp; $rec = substr($_,0,2); $_ = substr($_,2); if ($rec == 10) { $id = substr($_,0,5); $_ = substr($_,6); } $records{$id}{$rec}{'date'} = substr($_,0,10); if ($rec != 50 || !exists($records{$id}{50}{'data'})) { $records{$id}{$rec}{'data'} = substr($_,10); } else { $records{$id}{50}{'data'} .= ' ' . substr($_,10); } } for (sort keys %records) { $id = $_; print "$id\n"; for (sort keys (%{$records{$id}})) { print "$_ : ".$records{$id}{$_}{'date'}." : ".$records{$id}{$_ +}{'data'}."\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, by a general 5001.11.1997practitioner on not more than 1 patient 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.1997other than consulting rooms, by a general 5001.11.1997practitioner on not more than 1 patient
|
|---|