in reply to Sorting colon-delimited records

Assuming each item is a record in an array, a Schwartzian will do the trick:

my @new_array = map { $_->[0] } sort { $a->[1] cmp $b->[1] } map { [ $_, get_sortable_item($_) ] } @old_array; sub get_sortable_item { my $data = shift; return (split /:/, $data, 3)[1]; }


Update: Whoa! According to timestamps, I'm half an hour late with this node, but I swear that reply wasn't there when I just posted. Hmm... Oh well.

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.