Il giorno 05/mar/04, alle 11:53, Harald Joerg ha scritto:

Brett Sanger <[EMAIL PROTECTED]> writes:

So I have an array of hashrefs, that have date-related data (frex:
Month and year)

I've been asked to sort the output in most-recent-first order.

I tried: [% FOREACH Report = Reports.nsort('year').nsort('month') %]
(I expected this to be backwards, but I figured I'd mess with
reverse once I was sure this worked)

Reports.nsort('year') yields a list, sorted according to the years. Then you sort *this whole list* again, this time according to the month. This second nsort doesn't know nor care about values under the 'year' key.

I think it should be remembered the concept of stable sorting algorithm. From perldoc -f sort:

  Perl 5.6 and earlier used a quicksort algorithm to implement
  sort.  That algorithm was not stable, and could go quadratic.
  (A stable sort preserves the input order of elements that com-
  pare equal.  Although quicksort's run time is O(NlogN) when
  averaged over all arrays of length N, the time can be O(N**2),
  quadratic behavior, for some inputs.)  In 5.7, the quicksort
  implementation was replaced with a stable mergesort algorithm
  whose worst case behavior is O(NlogN).  But benchmarks indi-
  cated that for some inputs, on some platforms, the original
  quicksort was faster.  5.8 has a sort pragma for limited con-
  trol of the sort.

Just to be pedantic :)

cheers,
S.


_______________________________________________ templates mailing list [EMAIL PROTECTED] http://lists.template-toolkit.org/mailman/listinfo/templates

Reply via email to