Array-PrintCols
view release on metacpan or search on metacpan
PrintCols.pm view on Meta::CPAN
$VERSION = '2.6';
require 5.001;
use Exporter;
@ISA = (Exporter);
@EXPORT = qw( print_cols format_cols );
use Carp;
sub min(@);
sub max(@);
$PreSorted = 1; # if set, do not need to sort
# If users need to, they can set this variable externally:
#
# $Array::PrintCols::PreSorted = 0;
#
#
# format_cols \@array [, $col_width [, $total_width [, $indent ] ] ]
#
PrintCols.pm view on Meta::CPAN
# format_cols \%hash [, -$columns [, $total_width, [, $indent ] ] ]
#
#
# This used to be "print_cols", which always sent everything to STDOUT.
# Now, the work is done in "format_cols", which returns a string result.
# Thanks to Gisle Aas <aas@bergen.sn.no> for the suggestion)
#
# Routine to format an array of values in alphabetically vertically
# sorted columns.
sub format_cols($;@) {
my($array) = shift;
$array = $$array if ref($array) eq 'REF';
$array = [sort(keys(%$array))] if ref($array) eq 'HASH';
ref($array) eq 'ARRAY' or croak "arg 1 must be an ARRAY, HASH, or ARRAYREF\n";
my($col_width) = shift || 0;
my($total_width) = shift || $ENV{'COLUMNS'} || 80;
my($indent) = shift || 0;
my($key,$max_len,$cols,$fmt,$col,$rows,$row);
PrintCols.pm view on Meta::CPAN
for ($col = $row; $col <= $#$array; $col += $rows) {
$o .= sprintf $fmt,$array->[$col];
}
$o .= "\n";
}
$o;
}
# print_cols -- just print the results of format_cols.
sub print_cols($;@) {
my $aref = shift;
print format_cols($aref,@_);
}
sub min(@) {
my($min) = shift;
local($_);
foreach (@_) { $min = $_ if $min > $_; }
$min;
}
sub max(@) {
my($max) = shift;
local($_);
foreach (@_) { $max = $_ if $max < $_; }
$max;
}
1;
__END__
lib/Array/PrintCols.pm view on Meta::CPAN
$VERSION = '2.6';
require 5.001;
use Exporter;
@ISA = (Exporter);
@EXPORT = qw( print_cols format_cols );
use Carp;
sub min(@);
sub max(@);
$PreSorted = 1; # if set, do not need to sort
# If users need to, they can set this variable externally:
#
# $Array::PrintCols::PreSorted = 0;
#
#
# format_cols \@array [, $col_width [, $total_width [, $indent ] ] ]
#
lib/Array/PrintCols.pm view on Meta::CPAN
# format_cols \%hash [, -$columns [, $total_width, [, $indent ] ] ]
#
#
# This used to be "print_cols", which always sent everything to STDOUT.
# Now, the work is done in "format_cols", which returns a string result.
# Thanks to Gisle Aas <aas@bergen.sn.no> for the suggestion)
#
# Routine to format an array of values in alphabetically vertically
# sorted columns.
sub format_cols($;@) {
my($array) = shift;
$array = $$array if ref($array) eq 'REF';
$array = [sort(keys(%$array))] if ref($array) eq 'HASH';
ref($array) eq 'ARRAY' or croak "arg 1 must be an ARRAY, HASH, or ARRAYREF\n";
my($col_width) = shift || 0;
my($total_width) = shift || $ENV{'COLUMNS'} || 80;
my($indent) = shift || 0;
my($key,$max_len,$cols,$fmt,$col,$rows,$row);
lib/Array/PrintCols.pm view on Meta::CPAN
for ($col = $row; $col <= $#$array; $col += $rows) {
$o .= sprintf $fmt,$array->[$col];
}
$o .= "\n";
}
$o;
}
# print_cols -- just print the results of format_cols.
sub print_cols($;@) {
my $aref = shift;
print format_cols($aref,@_);
}
sub min(@) {
my($min) = shift;
local($_);
foreach (@_) { $min = $_ if $min > $_; }
$min;
}
sub max(@) {
my($max) = shift;
local($_);
foreach (@_) { $max = $_ if $max < $_; }
$max;
}
1;
__END__
( run in 0.582 second using v1.01-cache-2.11-cpan-65fba6d93b7 )