Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: sorting entires by date

by Aristotle (Chancellor)
on Jan 01, 2004 at 23:04 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2024-04-18 20:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found