Perl で次のデータ構造を location_id で並べ替えようとしています。
my $employees = $dbh->selectall_arrayref(qq[
SELECT name, type, code, emp_cat_id,
percentage, location_id
FROM table_1
],{ Slice => {} });
for my $row (@$employees) {
push @{
$args->{employees}{ $row->{emp_cat_id} }
}, $row;
}
例:
123 => [
{
percentage => 0.25,
code => "XYZ",
name => "John Doe",
type => "pt",
location_id => 001,
emp_cat_id => 123
}
],
555 => [
{
percentage => 0.50,
code => "ZZZ"
name => "Chris Cringle",
type => "ft",
location_id => 007,
emp_cat_id => 555
},
{
percentage => 0.25,
code => "XXX"
name => "Tom Thompson",
type => "pt",
location_id => 002,
emp_cat_id => 555
}
]
すべての emp_cat_id について、location_ids を昇順で持つ構造が必要です。
次のことを試しましたが、「行番号の無効コンテキストでの並べ替えの無駄な使用」または「行番号のスカラーコンテキストでの並べ替えの無駄な使用」エラーが発生します。
$args->{employees} = sort {
$a->{location_id} <=> $b->{location_id}
} $args->{employees};
ソートを理解するための助けをいただければ幸いです。