Katie, rather than do that, you could just do:
[% FOREACH blah = hash.keys.sort %] ... [% END %]

Technically, the hash.sort also sorts the keys and returns them, since it's stash 
entry looks like:

-- perl --
'sort'    => sub {
    my ($hash) = @_;
    [ sort { lc $hash->{$a} cmp lc $hash->{$b} } (keys %$hash) ];
},
-- perl --

(The difference being hash.keys.sort doesn't lowercase the keys when testing for 
sorting)

Also, rather than patch the Stash directly, you can just add methods to the stash in 
your code:

-- perl -- 
$Template::Stash::HASH_OPS->{new_method} = sub { ... };
-- perl --

Which is really handy for testing and much safer than mucking with Stash.pm and 
breaking your scripts by mistake!

> functionality currently in the system.  To add that 
> functionality I went
> into Stash.pm and added a line at line 94:
> 
>     'sortkeys'   => sub { [ sort keys %{ $_[0] } ] },
> 
> and now am able to sort my hashes based on keys.   


Reply via email to