-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathalign.pl
More file actions
35 lines (30 loc) · 743 Bytes
/
align.pl
File metadata and controls
35 lines (30 loc) · 743 Bytes
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
34
#!/usr/bin/perl
use strict;
my $delimiter = ',';
my $line;
my @words;
my @width;
my $idx;
my $kdx;
my @lines = <STDIN>;
for $line ( @lines ) {
chomp( $line );
@words = split( $delimiter, $line );
for ($idx = 0 ; $idx <= $#words ; $idx++) {
if ( !defined $width[$idx] || $width[$idx] < length($words[$idx])) {
$width[$idx] = length( $words[$idx] );
}
}
}
for $line (@lines) {
chomp( $line );
@words = split( $delimiter, $line );
for ($idx = 0 ; $idx <= $#words ; $idx++) {
print( "$words[$idx]" );
for ($kdx = length($words[$idx]) ; $kdx < $width[$idx] ; $kdx++) {
printf " ";
}
printf "|";
}
printf "\n";
}