in reply to Field data missing; copying from other field

To jump to the line of the manager you need to know where it is, this means that you have to loop through the whole data once to find the manager's index. So if you do that, you might as well go through the file once, and fill the holes as you loop through the data to print it in a file. Something like:

for (@line) { $employee = GetElement($_); $groups{$employee->[name]} = $employee->[group]; push @list, $employee; } for (@list) { $_->[group] = $groups{$_->[manager]} unless $_->[group]; print ToCsv($_); }

Or, in the spirit of TIMTOWTDI, you can use references so that the group of an employee and their manager actually refer to the same scalar, even if it is still unknown:

use Data::Dumper; my %people; while (<DATA>) { chomp; my ($name, $group, $manager) = split/,/; # Don't do that, use Text:: +CSV instead if ($group) { ${ $people{$name}{Group} } = $group; # Autovivification means: if +the reference exists, change the value, else, create a new reference } else { $people{$name}{Group} = \${ $people{$manager}{Group} }; # Autovivi +fication again } } print Dumper \%people; print ${ $people{"Woody Boyd"}{Group} }; __DATA__ Sam Malone,Cheers,Rebecca Howe Woody Boyd,,Rebecca Howe Rebecca Howe,Cheers,Rebecca's Manager

Edit: You all recognized TIMTOWTDI desguised as TIMTOWTDIT :)