我想使用以下代码段对哈希引用数组进行排序:
@order = sort { $VAR1->[$a]->{'tom'} <=> $VAR1->[$b]->{'tom'} } @$VAR1};
结构$VAR1
如下:
$VAR1 = [
{
'tom' => '2.5',
'color' => 'Johnson',
'book' => 'ANSA',
'dog' => 19
}, ...
这是我在排序时遇到的错误:
Use of uninitialized value in numeric comparison (<=>) at part2.pl line 47.
Use of uninitialized value in numeric comparison (<=>) at part2.pl line 47.
Use of reference "HASH(0xa91cd8)" as array index at part2.pl line 47.
Use of reference "HASH(0xa91d68)" as array index at part2.pl line 47.
Use of uninitialized value in numeric comparison (<=>) at part2.pl line 47.
Use of uninitialized value in numeric comparison (<=>) at part2.pl line 47.
Use of reference "HASH(0xa91df8)" as array index at part2.pl line 47.
Use of reference "HASH(0xa91e88)" as array index at part2.pl line 47.
Use of uninitialized value in numeric comparison (<=>) at part2.pl line 47.
Use of uninitialized value in numeric comparison (<=>) at part2.pl line 47.
Use of reference "HASH(0xa91f18)" as array index at part2.pl line 47.
Use of reference "HASH(0xa91fa8)" as array index at part2.pl line 47.
Use of uninitialized value in numeric comparison (<=>) at part2.pl line 47.
Use of uninitialized value in numeric comparison (<=>) at part2.pl line 47.
Use of reference "HASH(0xa92038)" as array index at part2.pl line 47.
Use of reference "HASH(0xa920c8)" as array index at part2.pl line 47.
Use of uninitialized value in numeric comparison (<=>) at part2.pl line 47.
Use of uninitialized value in numeric comparison (<=>) at part2.pl line 47.
Use of reference "HASH(0xa92158)" as array index at part2.pl line 47.
Use of reference "HASH(0xb9a2c0)" as array index at part2.pl line 47.
Use of uninitialized value in numeric comparison (<=>) at part2.pl line 47.
Use of uninitialized value in numeric comparison (<=>) at part2.pl line 47.
我的问题是:用于排序的正确语法是什么?我是否必须 grep 或映射任何东西才能完成此操作?
谢谢!