in reply to Sort options
($a) cmp ($b) is comparing the full strings, not just the alphabetics, so perl never gets to the second comparison (which should be or'ed, BTW). You need something like
my @split_list = qw{erez[11] dana[22] dana[0] erez[10] erez[1] erez[0] + dana[10]}; my @new_list = sort { ($a =~ /(\w+)/)[0] cmp ($b =~ /(\w+)/)[0] || ($a =~ /(\d+)/)[0] <=> ($b =~ /(\d+)/)[0] } @split_list; print "$_\n" for @new_list; __END__ dana[0] dana[10] dana[22] erez[0] erez[1] erez[10] erez[11]
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Sort options
by Perlbotics (Archbishop) on Aug 03, 2008 at 17:09 UTC | |
|
Re^2: Sort options
by erez_ez (Acolyte) on Aug 03, 2008 at 15:40 UTC | |
by jethro (Monsignor) on Aug 03, 2008 at 16:00 UTC |