in reply to Printing an array in columns - improvements?
#!/usr/bin/perl use strict; use warnings 'all'; my @array = qw/one two three four five six seven eight nine ten/; my $cols = 3; my $max = -1; $_ > $max && ($max = $_) for map {length} @array; while (@array) { print join " " => map {sprintf "%-${max}s" => $_} splice @array => 0, $cols; print "\n"; }
Abigail
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Printing an array in columns - improvements?
by BrowserUk (Patriarch) on Jul 18, 2002 at 16:57 UTC | |
by demerphq (Chancellor) on Jul 18, 2002 at 18:20 UTC |