use ihb::List::Util qw/ group transpose /; use List::Util qw/ max sum /; my @files = sort qw/ B Digest Filter MIME SDBM_File Time util ByteLoader DynaLoader GDBM_File NDBM_File Safe Unicode Cwd Encode I18N ODBM_File Socket XS DB_File Errno IO Opcode Storable attrs Data Fcntl IPC POSIX Sys re Devel File List PerlIO Thread threads /; my $width = 55; my $padding = 2; # Columnize my (@cols, @widths); for (my $rows = 1; 1; $rows++) { @cols = group($rows, @files); @{$cols[-1]} = grep defined, @{$cols[-1]}; @widths = map max(map length, @$_), @cols; my $tw = sum(@widths) + $padding * (@widths - 1); last if $tw < $width or $rows == @files; } # Format columns for (0 .. $#cols) { my $format = "%-$widths[$_]s"; for (@{$cols[$_]}) { $_ = sprintf $format, $_; } } # Output rows { local $" = ' ' x $padding; print "@$_\n" for transpose(@cols); }