in reply to A generic sorting problem
This way you can even sort numbers AND letters :@a = qw( words only contains ); @b = qw( 8 3 7 1 ); print join( " ", sort { $a <=> $b || $a cmp $b } @a ), "\n"; # contains only words print join( " ", sort { $a <=> $b || $a cmp $b } @b ), "\n"; # 1 3 7 8
@a = qw( 2 two 1 one ); print join( " ", sort { $a cmp $b || $a <=> $b } @a ), "\n"; # 1 2 one two
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: A generic sorting problem
by demerphq (Chancellor) on Jul 19, 2002 at 10:25 UTC | |
by choocroot (Friar) on Jul 19, 2002 at 13:22 UTC |