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

Re: Sorting a hash table - Advanced;)

Thread Previous
Tor Hildrum
February 28, 2002 05:16
Re: Sorting a hash table - Advanced;)
Message ID:
 >> 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
}                        ## end first foreach.

foreach $key (keys %runset) {
@array[$counter] = $runset{bar};
}                        ## 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 :)


Thread Previous Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About