Hi all,

I have written a piece of code which takes in to list of terms and retrieves the intersection between the two list of terms. The code works fine but it the intersection list has redundant in its terms. How do I fix this? The code is given below.

#!/usr/bin/perl -w

use Carp;
use strict;
use warnings;

# Takes in first argument
my ($input_file1, $input_file2 ) = @_;

# Opens the input files
    open my $fh, "<", $ARGV[0] or die "could not open $ARGV[0]: $!";
    my @list1 = <$fh>;


    open my $fh1, "<", $ARGV[1] or die "could not open $ARGV[1]: $!";
    my @list2 = <$fh1>;

# generates an intersection of terms from the first and second arguments
my @intersection_terms;
foreach (@list1)
{
    my $itemlist1 = $_;

    foreach (@list2)
    {
        my $itemlist2 = $_;

        if ($itemlist1 eq $itemlist2)
        {
            push @intersection_terms, $itemlist2;
        }
    }
}
print @intersection_terms, "\n";


exit 0;

 the sample result:

GO:0006366      transcription from RNA polymerase II promoter
GO:0005634      nucleus
GO:0005634      nucleus
GO:0005634      nucleus
GO:0005634      nucleus
GO:0005634      nucleus
GO:0042493      response to drug
GO:0042493      response to drug




I would appreciate if somebody could help me with this.

Thanks,

Aravind

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to