Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2017-07-25 16:45 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (376 votes). Check out past polls.