($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]
In reply to Re: Sort options
by FunkyMonk
in thread Sort options
by erez_ez
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |