in reply to split hash into two columns
my @keys = sort { $hash{$b} <=> $hash{$a} || $b cmp $a } keys %hash; my @col1 = splice(@keys, 0, $#keys/2+1); my @col2 = @keys; while (@col2) { my $key1 = shift(@col1); my $key2 = shift(@col2); printf "%s => %s\t%s => %s\n", $key1, $hash{$key1}, $key2, $hash{$key2}; } while (@col1) { my $key1 = shift(@col1); printf "%s => %s\n", $key1, $hash{$key1}; }
Updated and tested.
Incorrect original version:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: split hash into two columns
by Anonymous Monk on Mar 27, 2006 at 23:15 UTC | |
by ikegami (Patriarch) on Mar 27, 2006 at 23:48 UTC |