keiusui has asked for the wisdom of the Perl Monks concerning the following question:
$students{0354} = "Fred\t3.2"; $students{4873} = "Tom\t2.9"; $students{1522} = "Susan\t4.0";
I want to display all students sorted by the GPAs. I have the following code in place:
but I don't know what to put in the GPA_sort subroutine.foreach $key(sort GPA_sort %students) { #etc }
What code should I put the GPA_sort subroutine?
Is it something like the following?
sub GPA_sort { $value_a = $students->{$a}; $value_b = $students->{$b}; ($name_a, $gpa_a) = split(/\t/, $value_a); ($name_b, $gpa_b) = split(/\t/, $value_b); $gpa_a <=> $gpa_b }
Any help would be gratefully appreciated. Thank you.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: sorting by field of a tab-delimited hash value
by bobf (Monsignor) on Jun 18, 2006 at 22:15 UTC | |
|
Re: sorting by field of a tab-delimited hash value
by GrandFather (Saint) on Jun 18, 2006 at 22:23 UTC | |
|
Re: sorting by field of a tab-delimited hash value
by Zaxo (Archbishop) on Jun 19, 2006 at 02:16 UTC | |
by keiusui (Monk) on Jun 21, 2006 at 01:00 UTC | |
|
Re: sorting by field of a tab-delimited hash value
by jwkrahn (Abbot) on Jun 18, 2006 at 22:15 UTC | |
by keiusui (Monk) on Jun 18, 2006 at 22:21 UTC | |
|
Re: sorting by field of a tab-delimited hash value
by TedPride (Priest) on Jun 19, 2006 at 03:46 UTC | |
|
Re: sorting by field of a tab-delimited hash value
by sh1tn (Priest) on Jun 19, 2006 at 09:01 UTC | |
|
Re: sorting by field of a tab-delimited hash value
by salva (Canon) on Jun 20, 2006 at 10:00 UTC |