and would like to merge them to form an output file like this:
Output
A
BY
C
DW
E
FU
...
Basically every other line of the second file should be pasted onto every other line of the first file, preferably without tab or any other delimiter.
How do I manage this?
$ cat file1
A
B
C
D
E
F
$ cat file2
Z
Y
X
W
V
U
$ cat script.pl
use warnings;
use strict;
die qq[Usage: perl $0 <file-1> <file-2>\n] unless @ARGV == 2;
open my $fh1, qq[<], shift @ARGV or die qq[ERROR: $!\n];
open my $fh2, qq[<], shift @ARGV or die qq[ERROR: $!\n];
while ( my $data1 = <$fh1>, my $data2 = <$fh2> ) {
chomp ($data1, $data2);
if ( $. % 2 == 0 ) {
printf qq[%s%s\n], $data1, $data2;
}
else {
printf qq[%s\n], $data1;
}
}
$ perl script.pl file{1,2}
A
BY
C
DW
E
FU