in reply to Sort options
Just a quick one. It would probably be more efficient to run the regexp match only once and transform the list items into somthing like ({str => 'dana', num => 10},...).#!/usr/bin/perl use warnings; use strict; my @list = qw(erez[11] dana[22] dana[0] erez[10] erez[1] erez[0] dana[ +10]); my @sorted = sort sorter @list; print join ' ', @sorted; sub sorter { my ($a_str, $a_num) = ($a =~ /(\w+).(\d+)/); my ($b_str, $b_num) = ($b =~ /(\w+).(\d+)/); return $a_str cmp $b_str unless $a_str eq $b_str; return $a_num cmp $b_num; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Sort options
by broomduster (Priest) on Aug 03, 2008 at 16:54 UTC | |
by johngg (Canon) on Aug 03, 2008 at 23:10 UTC |