Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Sorting comma-delimited records

by Ovid (Cardinal)
on May 31, 2002 at 18:32 UTC ( #170797=note: print w/replies, xml ) Need Help??


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]; }

Cheers,
Ovid

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://170797]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (1)
As of 2021-04-14 00:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?