in reply to Re: How do you sort keys of a hash in descending order and print 3 per line?
in thread How do you sort keys of a hash in descending order and print 3 per line?

You can avoid mucking about with counters and stuff by making the implicit list in the for loop an explicit array then splice chunks off it:

#!/usr/bin/perl use warnings; use strict; my %accounts = ( tom => "BigApple", tom2 => "BigApple2", tom3 => "BigApple3", tom4 => "BigApple4", tom5 => "BigApple5", tom6 => "BigApple6", tom7 => "BigApple7", ); my @keys = reverse sort keys %accounts; print join ("\t", @$_), "\n" while @$_ = splice @keys, 0, 3;

Prints:

tom7 tom6 tom5 tom4 tom3 tom2 tom
Premature optimization is the root of all job security