- 论坛徽章:
- 1
|
本脚本把
my %last_name = qw {
fred flintstone Wilma Flintstone Barney Rubble
betty rubbel Bamm-Bamm Rubble PEBBLES FLINSTONE
};
进行sorting. 具体要求是:
Make a program that will print the following hash''s data sorted in case-insensitive
alphabetical order by last name ( 首先按姓排序, 不计大小写)
When the last names are the same. sort those by first name( again, without
regard for case) (当姓一样时,按名排序,不计大小写)
All of the people with same family name should be grouped together( 所有
姓相同的项应相邻)
The names should be printed with the same capitaliztion as shown here (
最后结果不改变原来的字母大小写)
# ./perlt
FLINSTONE, PEBBLES
flintstone, fred
Flintstone, Wilma
rubbel, betty
Rubble, Bamm-Bamm
Rubble, Barney
- #!/usr/local/bin/perl
- my %last_name = qw {
- fred flintstone Wilma Flintstone Barney Rubble
- betty rubbel Bamm-Bamm Rubble PEBBLES FLINSTONE
- };
- my @keys = sort {
- "L$last_name{$a}" cmp "L$last_name{$b}"
- or
- "L$a" cmp "L$b"
- } keys %last_name;
- foreach (@keys) {
- print "$last_name{$_}, $_
- ";
- }
复制代码 |
|