in reply to 'ls -C' column style

Sorry about the confusion just now.. Try something like this:
my @list = sort keys %Commands; $colwidth = length((sort {length($b) <=> length($a)} @list)[0] + ) +1; $ncol = int( $Users{$userid}{'screenwidth'}/$colwidth ); $nrow = int( scalar(@list) / $ncol ); $nrow++ if ( scalar(@list) % $ncol ); $fmt = "%-${colwidth}s"; foreach my $r ( 0 .. $nrow-1 ) { my $ind = @help; $help[$ind] = ''; foreach my $c ( 0 .. $ncol-1 ) { my $i = $c * $nrow + $r; $help[$ind] .= sprintf( $fmt, $list[$i] ) if($list[$i] +); } }
(Shamelessly cut&pasted from my own code, stolen from somewhere else, but I've forgotten where.. )

C.

Replies are listed 'Best First'.
Re^2: 'ls -C' column style
by hv (Prior) on Nov 04, 2004 at 20:43 UTC

    Thanks for that. This code is similar to the chunk in the Perl Power Tools 'ls' I mentioned in the OP - all columns are forced to be the same width as the widest, which can waste a lot of space if (for example) you have lots of narrow entries and one wide one.

    Hugo