in reply to Open file, sort data on matching field, close file

First you need to figure out how to parse those records out as records, and which type of record each one is. Then, a hash of hashes (HoH) of the records makes sense to organize them.

Something like the below makes sense to me as your data structure. Keying the outside hash to the common key for your tables allows you to add data to the anonymous hashes inside as you find new records for an employee, rather than having to put an employee record together completely before storing it in the data structure. Then, just walk over the outside hash and output the key and the data from inside the anonymous hash for each employee in turn.

@employee = ( '227' => { 'uid' => 'simpsonh', 'sn' => 'Simpson', 'givenname' => 'Homer', 'manager' => 'burnsm', 'telephoneNumber' => '2183445555', 'departmentNumber' => 38, 'title' => 'Nuclear Plant Operator', 'roomNumber' => 7, 'buildingName' => 'Nuclear Resources' }, 222 => { # rest of entry info here } );