我有这段代码:
use strict;
use warnings;
my %hash = ( 5328 => 'Adorable',
26191 => '"Giraffe"',
57491 => 'Is Very',
4915 => 'Cute',);
foreach (sort { ($hash{$a} cmp $hash{$b}) || ($a cmp $b) } keys %hash)
{ print "$hash{$_}\n"; }
这将产生以下结果:
"Giraffe"
Adorable
Cute
Is Very
我需要按字母顺序排列,并忽略AlphaNumeric字符前的特殊字符,例如此示例:
Adorable
Cute
"Giraffe"
Is Very
有什么建议吗?
<=>
而不是cmp
。 - Matt Jacob%hash
的数据来源是什么(请不要把变量命名为@array
、%hash
或$scalar
)。这个命名需要重写。 - Borodin