On Mon, 15 Dec 2003 00:17:17 -0800
"B. Rothstein" <[EMAIL PROTECTED]> wrote:
> I have a hash where each key is a first name linked to a last name, any
> suggestions on how to loop through the hash to sort the list by the last
> names?
Something like this perhaps?
#!/usr/bin/perl -w
use strict;
my %h = (
Jo => "Blow",
Al => "Smith",
Ok => "Corale"
);
foreach my $person(sort {$h{$a} cmp $h{$b} }
keys %h)
{
print "$person is $h{$person}\n";
}
__END__
Jo is Blow
Ok is Corale
Al is Smith
Straight from the Perl Cookbook
--
Owen
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>