How do you compare two columns of data and print the results. The values in one column is repeated so i want to compare with another column and print only once those values that match.
#!/usr/bin/perl -w use strict; use warnings; use Getopt::Std; my $file = "lethal_results2.txt"; # input file containing nubiscan res +ults my $ge = "geneid.txt"; # file with TE name and length open(FILE,"<",$file) or die("Unable to open file $file: $!"); open(GE,"<",$ge) or die("Unable to open $ge: $!"); my @file_data = <FILE>; my @ge_data = <GE>; #input stored in an array close(FILE); close(GE); foreach my $line (@ge_data) { my @line = split(/\s+/,$line); my $start = $line[0]; #print"$line[0] \n"; foreach my $values(@file_data) { my @values = split(/\s+/, $values); my $id = $values[0]; #print"$values[0] \n"; my $width = 11; if ($values[0] eq $line[0]) { #print"the gene id \n"; print"$line[0] \n"; } } }
This code prints all the values just as it is split does not compare and print them as i want it.. The column1 data:
ENSMUSG00000050310 ENSMUSG00000025583 ENSMUSG00000021198 ENSMUSG00000052595 ENSMUSG00000015243 ENSMUSG00000024130 ENSMUSG00000031333 ENSMUSG00000026842 ENSMUSG00000026596 ENSMUSG00000020532 ENSMUSG00000026003 ENSMUSG00000023328 ENSMUSG00000029580 ENSMUSG00000054808 ENSMUSG00000026836
Column 2:
ENSMUSG00000050310 ENSMUSG00000050310 ENSMUSG00000050310 ENSMUSG00000050310 ENSMUSG00000050310 ENSMUSG00000050310 ENSMUSG00000050310 ENSMUSG00000050310 ENSMUSG00000025583 ENSMUSG00000025583 ENSMUSG00000025583 ENSMUSG00000025583 ENSMUSG00000025583
In the second column the values are repeated so i want to compare the values in both columns and then print those present in both only once without repetition.

In reply to Comparing two columns by Nalababu

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.