Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: sorting entires by date

by Aristotle (Chancellor)
on Jan 01, 2004 at 23:04 UTC ( #318181=note: print w/replies, xml ) Need Help??

in reply to sorting entires by date

Basically you want a Schwartzian Transform. You parse the lines into a list of lists, sort it by the desired field, then extract the original data.
my @sorted = map $_->[0] sort { $a->[4] <=> $b->[4] } map [ $_, split /:/ ], <>;
Of course if you want to keep them around in the parsed form for later steps, you can leave out the copy of the line and the extraction step:
my @sorted = sort { $a->[4] <=> $b->[4] } map [ split /:/ ], <>;

I am too lazy to explain the Schwartzian transform all over again :), so I Super Searched for some explaination. Surprisingly I came up empty for the time being..

The probably most important to understand parts are references and how to use them to create complex data structures in Perl. If you understand that, the Transform itself should be almost self-explanatory. Check out perldoc perlreftut, perldoc perldsc, and perldoc perllol.

Makeshifts last the longest.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://318181]
and nobody stirs...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2018-06-21 05:23 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (117 votes). Check out past polls.