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

Re: Sorting a hash table - Advanced;)

Thread Previous
From:
Tor Hildrum
Date:
February 28, 2002 05:16
Subject:
Re: Sorting a hash table - Advanced;)
Message ID:
B8A3EC18.5763%torhildr@mac.com
 >> 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?

Answering my own post..
After reading this, I realized that you where probably talking about sorting
the specific keys.
Since I'm not really that advanced, it gets bloated fast.

My $counter = "0":
print "\n\n**Summary**\n";
foreach my $key (keys %runset){
   my $array[$counter] = $runset{foo}; ## assign value to array
$counter++;
}                        ## end first foreach.

foreach $key (keys %runset) {
@array[$counter] = $runset{bar};
$counter++;
}                        ## end second foreach


# .. other specific keys
## Now you can sort and print the array.

This probably isn't a good answer, but it might bring forth some of the
guru's :)

-- 
T.


Thread Previous


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