develooper Front page | perl.beginners | Postings from February 2002

Re: Sorting a hash table - Advanced;)

Thread Previous | Thread Next
From:
Tor Hildrum
Date:
February 28, 2002 05:01
Subject:
Re: Sorting a hash table - Advanced;)
Message ID:
B8A3E8AA.575B%torhildr@mac.com
On 27/2/02 17:33, "Steven M. Klass" <Steven.Klass@nsc.com> wrote:

> Hi all,
> 
> ok here is the fundamental code
> 
> print "\n\n**Summary**\n";
> foreach my $key (keys %runset){
>   printf ( "%-20s %-20s\n",$key, $runset{$key});
> }
> 
> Now I want to sort this hash for example
> print "\n\n**Summary**\n";
> foreach my $key (keys %runset){
>   print "Name        $runset{foo}"
>   # .. other specific keys
>   printf ( "%-20s %-20s\n",$key, $runset{$key});
> }
> 
> The question is how can I sort the remaining keys that I haven't already
> printed before.
> 
> Basically I want to format this so certain keys get printed in a certain
> order, but there may be some remaining keys that I want printed that I really
> don't care about.  (a "catch-all" if you will)
> 
> Thanks

print "\n\n**Summary**\n";
foreach my $key (keys %runset){
print "Name        $runset{foo}"
# .. other specific keys
foreach $key (sort keys %runset) {  ## sort the remaining in ASCII order.
printf ( "%-20s %-20s\n",$key, $runset{$key});
}

Something like that?

-- 
T.



Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About