On Wed, Mar 2, 2011 at 5:14 PM, Summer <[email protected]> wrote:

>
> I have some deep hashes and I am trying to sort them and I can't seem to do
> it.
> Here is an example.
>
> %popularshows
> --> %horror
> ------> %count
> %1
>   name => 'scary movie 3'
>   cost => '10'
> %2
>   name => 'Knife Attack'
>   cost => '9'
> %3
>   name => 'Frankenstein'
>   cost => '10'
>
>
> So I am trying:
>
> FOREACH val IN popularshows.horror.count.keys.sort('name')
>
> and variations on that, but I can't seem to sort them by their alphabetical
> names.
>
> Any ideas?
>

What is the result you're looking for?  A list of the %count's keys, or a
list of %count's values (each of which is a hash)?  If the former, I don't
believe you can do that with the built-in vmethods.  If the latter, try
this:

[% popularshows = {
     horror => {
       count => {
         '1' => {
           name => 'scary movie 3',
           cost => '10',
         },
         '2' => {
           name => 'Knife Attack',
           cost => '9',
         },
         '3' => {
           name => 'Frankenstein',
           cost => '10',
         },
       },
    },
  };
FOREACH val IN popularshows.horror.count.values.sort('name');
val.name _ "\n";
END %]

Ronald
_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates

Reply via email to