I'm having trouble figuring out how to return a hash I create in a sub function and if I should treat it like a reference when it's returned to my calling function. Here's what I have:
## calling function
sub calling_function {
my %sort_records = &setup_and_sort_records( \@rec );
#do something with sorted records.
}
sub setup_sort_rec {
my $rec = shift;
my %sort_rec;
my $key = "";
for ( my $index = 0; $index < @$rec; $index++ ) {
$key = $$rec[ $index ]{id} . '_';
$key .= $$rec[ $index ]{person} . '_';
$key .= $$rec[ $index ]{number} . '_';
$key .= $$rec[ $index ]{date} . '_';
$key .= $$rec[ $index ]{time};
$sort_rec( $key } = $index;
}
return %sort_rec;
}
If you see anything wrong here I would appreciate any help.
Thanks in advance,
Old Joe