in reply to 'ls -C' column style
(Shamelessly cut&pasted from my own code, stolen from somewhere else, but I've forgotten where.. )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] +); } }
C.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: 'ls -C' column style
by hv (Prior) on Nov 04, 2004 at 20:43 UTC |