[Catalyst] Sort something in the stash

phaylon phaylon at dunkelheit.at
Wed Jun 7 15:38:56 CEST 2006


Carl Franks said:
> 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} }

Well, just put that into the stash, like (untested):

  $c->stash->{ sort_by_key } = sub {
      my ( $ary, $key ) = @_;
      [ sort { $a->{ $key } cmp $b->{ $key } } @{ $ary } ];
  };

and use it like

  [% sorted_aryref = sort_by_key( unsorted_ary_ref, 'name' ) %]


hth,
p




More information about the Catalyst mailing list