kiat has asked for the wisdom of the Perl Monks concerning the following question:
I'm able to get the output I expected i.e. the sorted values (Keith 90, followed by Cliff 76 and so on).use strict; #use warnings; # I'm trying to simulate input from a textfile containing # lines of NameSpaceMarks my @names_marks = ("cliff 76", "john 52", "keith 90", "rob 52"); my (%hash, @names, @marks); foreach (@names_marks) { ($names[$_], $marks[$_]) = split / /, $_; $hash{"$marks[$_]".$names[$_]} = ucfirst($names[$_]). " " . $marks[$ +_]; } foreach my $key (sort {$b <=> $a} keys %hash) { # Prints each value print "\$key: $key \$value: $hash{$key}\n"; } #Output of print $key: 90keith $value: Keith 90 $key: 76cliff $value: Cliff 76 $key: 52rob $value: Rob 52 $key: 52john $value: John 52
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: sort hash elements...
by Chady (Priest) on Mar 27, 2002 at 12:30 UTC | |
by kiat (Vicar) on Mar 27, 2002 at 13:37 UTC | |
by Chady (Priest) on Mar 27, 2002 at 18:01 UTC | |
by kiat (Vicar) on Mar 28, 2002 at 09:41 UTC | |
|
Re: sort hash elements...
by particle (Vicar) on Mar 27, 2002 at 14:15 UTC | |
by kiat (Vicar) on Mar 27, 2002 at 15:06 UTC | |
by particle (Vicar) on Mar 27, 2002 at 16:26 UTC | |
by kiat (Vicar) on Mar 28, 2002 at 09:27 UTC | |
by particle (Vicar) on Mar 28, 2002 at 13:33 UTC |