Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Answer: How do I print a hash so that it represents actual table with column headers?

by toolic (Bishop)
on Sep 01, 2009 at 01:51 UTC ( #792514=categorized answer: print w/replies, xml ) Need Help??

Q&A > hashes > How do I print a hash so that it represents actual table with column headers? - Answer contributed by toolic

Text::Table can be used to format the keys and values of a simple hash as a 2-column table. It automatically calculates the width of each column.
use Text::Table; my $tb = Text::Table->new(qw(Keys Values)); # column headers for my $k (keys %hash) { $tb->add($k, $hash{$k}) } print $tb;

  • Comment on Answer: How do I print a hash so that it represents actual table with column headers?
  • Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2016-09-28 14:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Extraterrestrials haven't visited the Earth yet because:







    Results (532 votes). Check out past polls.