Octavian Rasnita
2005-06-18 12:06:12 UTC
Hi,
I have a hash reference like:
$ref = {
id1 => {
title => 'first title',
number => 123,
},
id2 => {
title => 'the second title',
number => 234,
},
id3 => {
title => 'the third title',
number => 345,
},
};
And I want to print the values in a template, sorting the titles by
"number", in html links, something like:
$vars = {
ref => $ref,
};
$tt->process("file.html", $vars);
The file file.html:
[% FOREACH r = ref.keys %]
<a href="/program?id=[% r %]">[% ref.title _ " " _ ref.number %]</a>
[% END %]
But I want those links be sorted by the ref.number. Is it possible? Or I
need to create another array with the keys of the hash I want to sort in
order and then loop that array?
Thank you.
Teddy
I have a hash reference like:
$ref = {
id1 => {
title => 'first title',
number => 123,
},
id2 => {
title => 'the second title',
number => 234,
},
id3 => {
title => 'the third title',
number => 345,
},
};
And I want to print the values in a template, sorting the titles by
"number", in html links, something like:
$vars = {
ref => $ref,
};
$tt->process("file.html", $vars);
The file file.html:
[% FOREACH r = ref.keys %]
<a href="/program?id=[% r %]">[% ref.title _ " " _ ref.number %]</a>
[% END %]
But I want those links be sorted by the ref.number. Is it possible? Or I
need to create another array with the keys of the hash I want to sort in
order and then loop that array?
Thank you.
Teddy