in reply to Print Array items in Fixed width
"%10s" is used to format "!W31801!\t!919!\t!90200809!\t!840!\t!MO!", more than 10 characters, so you might as well have used "%s". You need to apply "%10s" (actually "%-10s" if you want to left-justify) to every field of every line, not just every line.
orprint('-', (map { sprintf('%-10s', $_) } @header), "\n"); foreach my $line (@data) { my @fields = split(/-->/, $line); print('-', (map { sprintf('%-10s', $_) } @fields), "\n"); }
my $format = '-' . ('%-10s' x @header) . "\n"; printf($format, @header); foreach my $line (@data) { printf($format, split(/-->/, $line)); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Print Array items in Fixed width
by harishnuti (Beadle) on Jul 31, 2008 at 05:09 UTC |