Andrew Beattie wrote:
> I have a hash.
>   [% hash = { barney => 4, Wilma => 3, fred => 2, betty => 1 } %]
[...]
> But I'm coming unstuck when I try to do it ordered by the values:

Dave Cash wrote:
> I do this with two virtual hash methods called vsort and nvsort:

You can also acheive it, in a roundabout way, like so:

  [% hash = { barney => 4, Wilma => 3, fred => 2, betty => 1 } %]

  [% FOREACH n = hash.list.sort('value') -%]
    * [% n.value %]: [% n.key %]
  [% END %]

The "hash.list" part converts the hash into a list of hashes, each
having a 'key' and 'value' entry:

    [ { key => 'barney', value => 4 }
      { key => 'Wilma',  value => 3 }
      { key => 'fred',   value => 2 }
      { key => 'betty',  value => 1 } ]

Then the ".sort('value')" part sorts the list, using the 'value'
key to of each hash ref as the sort criteria.

A

      

_______________________________________________
templates mailing list
[EMAIL PROTECTED]
http://lists.ourshack.com/mailman/listinfo/templates

Reply via email to