Hi everyone,

I have written a code that takes in two files (containing a set of terms) as arguments
 eg: testfile1

CCO:P0000056    cell cycle
CCO:U0000002    cell-cycle process
CCO:P0000308    cell cycle process
CCO:P0000004    regulation of progression through cell cycle
CCO:P0000005    cell cycle checkpoint
CCO:U0000000    cell-cycle entity
CCO:P0000294    regulation of cell cycle

reads the contents and gets an intersection (common terms) from the two file. but the on implementation its throwing me the following errors:

Use of uninitialized value $input_file1 in open at get_intersection_terms_from.pl line 9. readline() on closed filehandle FILEONE at get_intersection_terms_from.pl line 11. Use of uninitialized value $input_file2 in open at get_intersection_terms_from.pl line 16. readline() on closed filehandle FILETWO at get_intersection_terms_from.pl line 18.

the code is given below:


#!/usr/local/bin/perl -w

use Carp;
use strict;
use warnings;

# Takes in first argument
my $input_file1 = $_;
open (FILEONE, $input_file1);

my @list1 = <FILEONE>;


# Takes in first argument
my $input_file2 = $_;
open (FILETWO, $input_file2);

my @list2 = <FILETWO>;


# 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 $itemlist2->id();
            print "\t", $itemlist2->name() if (defined $itemlist2->name());
            print "\n";

        }
    }
}

close FILEONE;
close FILETWO;

exit 0;

Could some guide me on this as to where I have gone wrong (I am new to programming in perl)?

thanks a lot,

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