summaryrefslogtreecommitdiffstats
path: root/clerk_column.pl
blob: 34f653188c634d270ddfc7c22d1a475f35e1e1e1 (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
#!/usr/bin/perl

# written by Florian Pritz <bluewind@xinu.at>

use Data::Dumper;
my %width = ();
my @lines = ();
while (my $line = <>) {
	chomp $line;
	push @lines, $line;
	my @parts = split(/\t/, $line);
	my $counter = 0;
	for (; $counter < @parts; $counter++) {
		my $partlen = length($parts[$counter]);
		$width{$counter} = $partlen if !defined($width{$counter}) or $partlen > $width{$counter}
	}
}

for my $line (@lines) {
	my @parts = split(/\t/, $line);
	my $counter = 0;
	for (; $counter < @parts - 1; $counter++) {
	  $parts[$counter] =~ s/\s+$//;
		my $partlen = $width{$counter};
		printf "%-*s\t", $partlen, $parts[$counter];
	}
	printf "%s\n", $parts[-1];
}