Array-Columnize
view release on metacpan or search on metacpan
lib/Array/Columnize/columnize.pm view on Meta::CPAN
=head1 Subroutines
=head2 cell_size
Return the length of String I<cell>. If Boolean I<term_adjust> is true,
ignore terminal sequences in I<cell>.
=cut
sub cell_size($$) {
my ($cell, $term_adjust) = @_;
$cell =~ s/\e\[.*?m//g if $term_adjust;
return length($cell);
}
=head2 columnize
Return a list of strings with embedded newlines (\n) as a compact
set of columns arranged horizontally or vertically.
lib/Array/Columnize/columnize.pm view on Meta::CPAN
Each column is only as wide possible, no larger than
C<$opts->{displaywidth}>. If I<aref>is not an array reference, the
empty string, '', is returned. By default, columns are separated by
two spaces - one was not legible enough. Set C<$opts->{colsep}> to
adjust the string separate columns. If C<$opts->{arrange_vertical} is
set false, consecutive items will go across, left to right, top to
bottom.
=cut
sub columnize($;$) {
my($aref, $opts) = @_;
my @l = @$aref;
# Some degenerate cases
# FIXME test for arrayness
# return '' if $aref is not an array
return "<empty>\n" if 0 == scalar(@l);
$opts = {} unless $opts;
merge_config $opts;
if ($opts->{arrange_array}) {
lib/Array/Columnize/options.pm view on Meta::CPAN
colsep => ' ',
displaywidth => $ENV{'COLUMNS'} || 80,
lineprefix => '',
linesuffix => "\n",
ljust => 'auto',
term_adjust => 0
};
# Merge in default configuration options into the passed hash reference.
# Values already set in the hash are untouched.
sub merge_config(%) {
my $config = shift;
while (($field, $default_value) = each %$DEFAULT_OPTS) {
$config->{$field} = $default_value unless defined $config->{$field};
};
}
if (__FILE__ eq $0 ) {
my %config;
merge_config \%config;
require Data::Dumper;
( run in 0.252 second using v1.01-cache-2.11-cpan-65fba6d93b7 )