diff options
Diffstat (limited to 'column.pl')
-rw-r--r-- | column.pl | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/column.pl b/column.pl new file mode 100644 index 0000000..87290af --- /dev/null +++ b/column.pl @@ -0,0 +1,27 @@ +#!/usr/bin/perl + +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; $counter++) { + my $partlen = $width{$counter}; + printf "%-*s | ", $partlen, $parts[$counter]; + } + printf "\n"; +} + +#print Dumper(\%width); |