in reply to Re: Sort options
in thread Sort options
It would probably be more efficient to run the regexp match only onceMaybe overkill here, but why not a Schwartzian?
use strict; use warnings; my @split_list = qw( erez[11] dana[22] dana[0] erez[10] erez[1] erez[0] dana[10] ); print "Before: @split_list\n"; my @new_list = map { $_->[0] } sort { $a->[1][0] cmp $b->[1][0] or $a->[1][1] <=> $b->[1][1] } map { [ $_, [ (/(\w+).(\d+)/) ] ] } @split_list; print "After: @new_list\n";
Before: erez[11] dana[22] dana[0] erez[10] erez[1] erez[0] dana[10] After: dana[0] dana[10] dana[22] erez[0] erez[1] erez[10] erez[11]
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Sort options
by johngg (Canon) on Aug 03, 2008 at 23:10 UTC |