Hi all,
I wonder if these abilities may be added?
1) Sort lists of lists
This seems super-easy:
--------------
459a460,462
> elsif (ref($item) eq 'ARRAY') {
> @keys = map { $item->[ $_ ] } @$fields;
> }
--------------
2) Sort hashes by key/index
So, if you have
%myhash = (
'foo' => [ 'bar, 'baz' ],
'qux' => [ 'quux', 'qquux' ],
);
...we would be able to sort this in TT by doing
[% myhash.sort(0) %]
...to return a list of hash keys sorted by the first element in each array.
Perhaps the following?
----------------------
sub hash_sort {
my ($hash, @fields) = @_;
my (@keys, @values);
foreach (keys %$hash) {
push @values, [ scalar @keys =>
_list_sort_make_key($hash->{$_}, @fields) ];
push @keys, $_;
}
my @sorted_values = sort { $a->[1] cmp $b->[1] } @values;
return [ map { $keys[ $_->[0] ] } @sorted_values ];
}
----------------------
-FG
--
Felipe Gasper
Linux/BSD development
cPanel of Texas, LLC
3701 Kirby Dr., suite 428
Houston, TX 77098
office 713-529-0800 x4096
cell 832-633-8092
fax 713-559-3206
_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates