in reply to Re^3: sorting hash by value when value is an array ref
in thread sorting hash by value when value is an array ref

I pass the @sorted to the template( it is perl, it's the Template-Toolkit). I pass it like this.
my $vars = { homework => \%homeworkHash, homeworks => \@sorted, }; my $tt = Template->new({ INCLUDE_PATH => "/inetpub/wwwroot/lib", WRAPPER => 'wrapperInstructor.htm', }); $tt->process('ClassGrades.htm', $vars)||die $tt->error();
The Template then uses the array named homeworks which is identical to @sorted in the perl script. The [% FOREACH key IN homeworks %] just iterates through the array and prints inserts each element into the hash to get the value.

Replies are listed 'Best First'.
Re^5: sorting hash by value when value is an array ref
by beachguy82 (Novice) on Nov 16, 2004 at 03:23 UTC
    If I pass a list of the keys to the template, everything prints out fine. So I'm assuming there must be a problem in my perl script.
      Thank you for you help. As it turned out I had that part of the code in a loop and it was causing the array to be overwritten. Thanks again for your help.
      I'm noticing that template toolkit may do some default alphabetical sorting on hashes. This could explain your problem too.