# populate the boss's part of the orgchart with employee numbers that report to him/her while (my ($loccode, $empnum, $bossnum, $name, $area) = $sth->fetchrow_array) { $boss{$empnum} = $bossnum; $name{$empnum} = $name; $area{$empnum} = $area; $loccode{$empnum} = $loccode; push @{$chart{$bossnum}}, $empnum; } # later, while working through the orgchart sub printreports { my $number = shift(@_); my $indent = shift(@_)." "; return unless defined @{$chart{$number}}; print "$indent$loccode{$number} $area{$number}:\n$indent*$name{$number} $number\n"; my @reports = @{$chart{$number}}; foreach my $peon (@reports) { next if $number == $peon; print "$indent$name{$peon} $peon $loccode{$number}\n"; printreports($peon, $indent) if $depth eq "recursive"; } }