Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^3: Sorting dates with the Schwartzian Transform

by johngg (Abbot)
on Aug 03, 2011 at 22:42 UTC ( #918400=note: print w/replies, xml ) Need Help??


in reply to Re^2: Sorting dates with the Schwartzian Transform
in thread Sorting dates with the Schwartzian Transform

... how I would know that the map {} sort {} map {} would be executed in reverse order, but I didn't find it. Any clues?

Both map and sort take a list (which is on the RHS), do some transformation of it then return the transformed list (to the LHS).

my @mapped = map { # some transform code } @unmapped; my @sorted = sort { # sorting code } @unsorted;

The ST code is just an extension of this right-to-left pattern:

  • the first map extracts the sorted dates in the original DD-MM-YYYY format and assigns to the @dates array on the LHS of the assignment operator (=);

  • but it can't do that before the sort has evaluated, sorting the items;

  • which in turn can't do any sorting before the bottom (or rightmost) map has transformed some dates into something sort can work with, taking its raw material from the rightmost part of the expression which is the original, unsorted @dates array.

I hope this makes things a bit clearer.

Cheers,

JohnGG

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://918400]
help
Chatterbox?
[1nickt]: stevieb it's just a simple web page with a POST form. You can set the attribute so when the user's browser opens a file manager to select a file to upload, it will only show those o f the type you want to get.
[1nickt]: Question for my learned friends: is there a word meaning "CSV-like" i.e. I want to say that I accept CSV files, but the separator doesn;t have to be a comma. Or is that implicit these days?
[chacham]: dsv

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2017-07-22 18:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (340 votes). Check out past polls.