Workshop in Computational Bioskills - Intersect.pl

#!/usr/bin/perl -w

$file1 = "list1";
$file2 = "list2";

open (FIRST,"<$file1") || die "cannot open list1\n";
open (SECOND, "<$file2") || die  "cannot open list1\n";

while ($line = <FIRST>)
{
    chomp $line;
    $hash{ $line } = 1;
}

close FIRST;

while ($newLine = <SECOND>)
{
    chomp $newLine;
    if (exists $hash{ $newLine })
    {
	print  "$newLine\n";
    }
}

close SECOND;