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


In reply to Matching columns between files by gggg

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.