in reply to Printing an array in columns - improvements?
use strict; my @array = qw/one two three four five six seven eight nine ten/; my $cols = 3; my $max = 0; $max < length($_) and $max = length($_) for @array; my $output = ""; my @copy = @array; while (@copy) { $output .= join(" ", map sprintf("%-${max}s", $_), splice @copy, 0, +3)."\n"; } print $output;
-- Randal L. Schwartz, Perl hacker
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: •Re: Printing an array in columns - improvements?
by fireartist (Chaplain) on Jul 18, 2002 at 15:39 UTC |