[Catalyst] Sort something in the stash

Carl Franks fireartist at gmail.com
Wed Jun 7 15:18:07 CEST 2006


On 07/06/06, Ryan <god at detz.net> wrote:
> This probably already exists in perl but it's something I've come upon a
> few times and I was seeing if there was a way to do it.
>
> I use Template to view the pages so for data I store it in a array of
> hashes so I can loop and grab the data.
>
> $c->stash->{results}->[0]->{id} = 1;
> $c->stash->{results}->[0]->{name} = 'test';
>
> Something like that...and I want to be able to sort on say 'name' in that
> structure. Anyone know an easy way to sort by an array of hashes on a key?

I don't know how to translate it into TT, but in perl it would be:

sort { $a->{name} cmp $b->{name} } @{ $c->stash->{results} }



More information about the Catalyst mailing list