I want to print out the second column of two files. Eventually I'm going to print it into another file but right now I just want to output it to the terminal. I tried doing this by making an array of the two files. Here is my code, but it returns nothing.
unless (open COL1, '<'. $file1) {die "Couldn't open '$file1'\n";}
unless (open COL2, '<'. $file2) {die "Couldn't open '$file2'\n";}
while (!eof(COL1) and !eof(COL2)) {
my @line = [<COL1>, <COL2>];
#my $line2 = <COL2>;
foreach my $line (@line) {
foreach my $row ($line){
my @column2 = split( /\t/, $row);
print $column2[1];
}
}
}
close COL1;
close COL2;
If I do the inner for loop for only a single file it works fine. Here is my code for a single file:
unless (open COL1, $file1) {die "\nUnable to open '$spare_f2;\n";}
foreach my $row (<COL1>) {
my @column2 = split( /\t/, $row);
print $column2[1];
}
close COL1;
A dirty fix would be to just copy paste the same code and do it for the second file, but I would like to have it working with an array so a single foreach loop can handle them both.