in reply to Re: Re: "numeric" sort of keys?
in thread "numeric" sort of keys?

Gorio3721,
My first attempt at the Schwartzian Transform.
#!/usr/bin/perl -w use strict; my @keys = qw (CMS5 Drive1 Drive2 Drive10 IRMA1 IRMA13 IRMA2); my %hash; @hash{@keys} = (); for my $key ( custom_sort(\%hash) ) { print "Key: $key\n"; } sub custom_sort { my $hash = shift; return map { $_->[0] } sort { $a->[1] cmp $b->[1] || $a->[2] <=> $b->[2]} map { [ $_, /(\w+?)(\d+)$/ ] } keys %$hash; } __END__ Key: CMS5 Key: Drive1 Key: Drive2 Key: Drive10 Key: IRMA1 Key: IRMA2 Key: IRMA13

Cheers - L~R