anonym has asked for the wisdom of the Perl Monks concerning the following question:
Hi, I am trying to match the three columns (first three) of one file with the columns 0,3,4 of the second file using perl.My code so far is
#!usr/bin/perl use strict; use warnings; my $infile1 = $ARGV[0]; my $infile2 = $ARGV[1]; my $outfile = $ARGV[2]; open (INFILE1,"<", $infile1) || die "Cannot open $infile1:$!\n"; open (INFILE2, "<", $infile2) || die "Cannot open $infile2:$!\n"; open (OUTFILE, ">", $outfile) || die "Cannot open $outfile:$!\n"; my @array1; my @array2; my @array3; my @array4; my $_; while (<INFILE1>) { chomp; @array1 = split (' ', $_); push (@array2, "@array1\n"); #print "@array2\n"; } while (<INFILE2>) { chomp; @array3 = split (' ', $_); push (@array4, "@array3\n"); #print "@array4\n"; } #print "@array2\n"; #print "@array4\n"; foreach my $array2(@array2) { my @line = split(/\s+/,$array2); my $chr1 = $line[0]; my $start1 = $line[1]; my $end1 = $line[2]; #print "$line[0]\n"; foreach my $array4(@array4) { my @values = split(/\s+/, $array4); my $chr2 = $values[0]; my $start2 = $values[3]; my $end2 = $values[4]; if (($chr1 eq $chr2 ) && ($start1 eq $start2) && ($end1 eq $end2)) + { #print "$start2\n"; print "$chr2\t$start2\t$end2\n"; } } }
please help me with this code.Thanks.
|
|---|