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: &bull;Re: Printing an array in columns - improvements?
by fireartist (Chaplain) on Jul 18, 2002 at 15:39 UTC
    Thanks!

    I'm just printed out the 'map' perldoc so I can figure out exactly what's happening.

    I found it interesting that you can
    splice(@array, 0, 3)
    Even if there's not 3 indices left in the @array.