我的清单为
@emprecords = (
['pavan',24,25000],
['kumar',25,35000],
['ajay',22,35000],
['vijay',25,20000]
);
我需要先按最低年龄和最高工资对它们进行排序。
我的清单为
@emprecords = (
['pavan',24,25000],
['kumar',25,35000],
['ajay',22,35000],
['vijay',25,20000]
);
我需要先按最低年龄和最高工资对它们进行排序。
用于<=>
数字比较和or
在年龄相等时检查薪水的条件:
#!/usr/bin/env perl
use strict;
use warnings;
use Data::Dumper;
my @emprecords = sort {
$a->[1] <=> $b->[1]
or
$b->[2] <=> $a->[2]
}
( ['pavan',24,25000],
['kumar',25,35000],
['ajay',22,35000],
['vijay',25,20000]
);
print Dumper \@emprecords;
像这样运行它:
perl script.pl
这会产生:
$VAR1 = [
[
'ajay',
22,
35000
],
[
'pavan',
24,
25000
],
[
'kumar',
25,
35000
],
[
'vijay',
25,
20000
]
];