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.


In reply to Compare three columns of one file with three columns of another file in perl by anonym

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.