in reply to Re: Structured Printing of Hash of Arrays
in thread Structured Printing of Hash of Arrays

I was just going to mention that "%-20s" is probably more what was wanted than "%20s" (yes, annoying how printf defaults to right-justifaction for non-numeric formats). Then I noticed no double underlines and that you assume that all of the arrays have the same number of elements. Finally, I went with "%-19s" which fits nicely on screens that are a multiple of 20 characters wide.

my @keys= sort keys %TOP; my $format= join( " ", ("%-19s") x @keys ) . "\n"; printf $format, @keys; printf $format, map { "=" x length($_) } @keys; my $line= 0; while( grep { $line <= $#{$TOP{$_}} } @keys ) { printf $format, map { def($TOP{$_}[$line]) } @keys; $line++; } sub def { return defined $_[0] ? $_[0] : def($_[1],""); }

        - tye (but my friends call me "Tye")

Replies are listed 'Best First'.
RE: (tye)Re: Structured Printing of Hash of Arrays
by merlyn (Sage) on Oct 12, 2000 at 01:54 UTC