summaryrefslogtreecommitdiff
path: root/word-aligner/paste-parallel-files.pl
blob: ce53b3255c7a45c5a2a5ddb38e69bb1e4d5cd055 (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
34
35
#!/usr/bin/perl -w
use strict;

my @fs = ();
for my $file (@ARGV) {
  my $fh;
  open $fh, "<$file" or die "Can't open $file for reading: $!";
  push @fs, $fh;
}
my $num = scalar @fs;
die "Usage: $0 file1.txt file2.txt [...]\n" unless $num > 1;

my $first = $fs[0];
while(<$first>) {
  chomp;
  my @out = ();
  push @out, $_;
  for (my $i=1; $i < $num; $i++) {
    my $f = $fs[$i];
    my $line = <$f>;
    die "Mismatched number of lines!" unless defined $line;
    chomp $line;
    push @out, $line;
  }
  print join(' ||| ', @out) . "\n";
}

for my $fh (@fs) {
  my $x=<$fh>;
  die "Mismatched number of lines!" if defined $x;
  close $fh;
}

exit 0;