Subject: | Data Dumper Tabulate |
i would be really handy to be able to dump data in a tabular form, a
Data::Dumper with style.
The below works for an array of HASHes, easy to extend - do you think
this fits in with your module, Text::Table, or should I wrap it up and
put it in its own module?
Lee
our @EXPORT = qw( Tabulate );
sub Tabulate {
my $rows = shift;
my $tb;
my @headers;
foreach my $i ( @$rows ){
my $row = $i;
if (ref $row eq 'HASH'){
if (not @headers){
@headers = sort keys %$row;
$tb = Text::Table->new(@headers);
}
$row = [ @{$row}{@headers} ];
}
$tb->load( $row );
}
return $tb;
}