blob: dcc934fa286133d0149767556bfa8f01ab27c2af (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
#! /usr/bin/perl -w
## not very scalable; stores entire document in memory
use strict;
use List::Util qw[min max];
main:{
## leftmost column is column ZERO
my @cwid = (); # width of column
my @store = ();
while (my $line = <>){
chomp $line;
my @stuff = split(' ', $line);
for (my $ii = 0; $ii < 0+@stuff; $ii++){
my $old = $cwid[$ii] || 0;
$cwid[$ii] = max(length($stuff[$ii]), $old);
}
push @store, \@stuff;
}
foreach my $line (@store) {
my @stuff = @$line;
for (my $ii = 0; $ii < 0+@stuff; $ii++){
if ($ii) {
print " ";
}
printf("\%-$cwid[$ii]s", $stuff[$ii]);
}
print "\n";
}
}
|