On Mar 10, 2005, at 7:35 AM, Randal L. Schwartz wrote:

"David" == David Jantzen <[EMAIL PROTECTED]> writes:

David> # Now onto the magic of the ST: map/sort/map. (Read from bottom
David> to top)


David> print # the results of the inner map
David> map {
David> $_->[0][3] = UnixDate($_->[1], "%B %e, %Y"); # translate back
David> to our human readable date
David> join(':', @{$_->[0]}), "\n"; # dereference the array
David> containing our values and join them together
David> } sort {
David> $category_table{$a->[0][1]} <=> $category_table{$b->[0][1]} #
David> sort on category
David> || Date_Cmp($a->[0][3], $b->[1]) # or sort on date


if Date_Cmp is expensive, the dates should be decoded in the first
map block to an easier-to-compare analogue.  The whole point of the ST
is to keep the computations in the sort to an *absolute minimum*.

Also, the assymetry of $a->[0][3] and $b->[1] seems very very broken.
Every reference you make to $a in the sort block should have the *identical*
reference to $b. Always. Always.

Yup, you're right. That line should read:

  || Date_Cmp($a->[1], $b->[1]) # or sort on date

It worked (accidentally) on the small sample so I didn't notice it.


David> } map {
David> chomp;
David> my @row = split(/:/, $_);
David> [EMAIL PROTECTED], ParseDate($row[3])]; # pass out an array of the @row
David> and dates to compare
David> } @current_deals;


Just another sorting expert, :)

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


Reply via email to