If the -1 index bothers you, you can build the list backwards. In the else clause, unshift instead of push, then you can use refer to the front of the list with [0] instead of the end with [-1]. Then when it's done, use reverse to get the original order. Given that, you have to decide if you want to have to take the extra step to reverse the list, or live with the odd look of [-1].
foreach my $case ( @{$all_cases} ) {
if ( $case_list
&& $case->{examiner} eq $case_list->[0]->{examiner} ) {
push @{ $case_list->[0]->{casedata} }, $case;
}
else {
unshift @{$case_list},
{
examiner => $case->{examiner},
casedata => [$case]
};
}
}
@{$case_list} = reverse @{$case_list};
|