Often in Perl I want to print out column/row data, say, from a hash.
This is simple:
foreach my $k(keys %h)
{
print $k, "\t", $h{$k}, "\n";
}
However, if the key happens to have a varying length, then the formatting just looks very jagged. I’ve investigated format, and it’s typically too heavyweight for what I’m looking for, which is a ‘simple’ column-row aligning pretty-printer.
I think you’ll find
printfuseful. Here is a small example:Long values are not truncated, and you can change text alignment inside the block:
%10s– means string type of length 10 (left aligned)%-10s– means string type of length 10 (right aligned)A full list of formats is on the
sprintfman page.