Hi all,
I am having two input files where I have to match columns 1,2,3 of one infile with columns 2,3,4 of second and i have to print for the matched lines the values in column 4 of second infile. I have made two separate arrays for each infile . Here is the script below :
use strict;
use warnings;
my $infile1 = $ARGV[0];
my $infile2 = $ARGV[1];
my $outfile = $ARGV[2];
unless (open( INFILE1, $infile1)) {
die "Cannot open $infile1\n";
}
my @array;
my @slice;
my @array1;
my @slice1;
my $element;
while(<INFILE1>) {
chomp;
my @array = split ('\t', $_);
my @slice = @array[0,1,2];
}
open (INFILE2, "<", $infile2) || die "cannot open $infile2";
open (OFILE, ">", $outfile) || die "cannot open $outfile";
my $i = 0;
while (<INFILE2>) {
chomp;
my @array1 = split ('\t', $_);
my @slice1 = @array1[1,2,3,4];
$slice1[0] = s/chr//g;
for ($i=0; $i < $#slice1; $i++) {
foreach my $element (@slice) {
print OFILE $slice1[3] ."\n";
}
else {
print OFILE "NA\n";
}
}
}
}
Any help would be appreciated.
Thanks