in reply to sort after first char of hash key

Just use substr to extract the proper values to sort by

my @list = map {"E$_"} (1..20); for my $k (sort {substr($a, 1) <=> substr($b, 1)} @list) { print "$k "; }

Note: If your keys don't actually all start with E, but you instead want to sort first by the alpha section and then numerically by the integer suffix, then you simply must extract the sections before sorting like so:

my @list = ("A15", "Y2", map {"E$_"} (1..20)); for my $k ( map {$_->[0]} sort {$a->[1] cmp $b->[1] || $a->[2] <=> $b->[2]} map {[$_, /(\D+)(\d+)/]} @list ) { print "$k "; }

Replies are listed 'Best First'.
Re^2: sort after first char of hash key
by danj35 (Sexton) on Jun 02, 2011 at 16:37 UTC

    Excellent suggestion and one I should have thought of before. It is near the end of the week...