try this
#!/usr/bin/perl
use warnings;
use strict;
my %bow1 = ();
my $file1 = shift;
open (FILE1, "$file1")or die "could not open FILE1:$file1; # Open firs
+t file
while (<FILE1>) {
my ($ID1, undef, undef, undef, $Seq1) = split;
$bow1{$ID1} = $ID1; # your id is the key and can be got again
}
close FILE1;
my $file2 = shift;
open (FILE2, "$file2")or die "could not open FILE2:$file2"; # Open sec
+ond file
while (<FILE2>) {
my ($ID2, undef, undef, undef, $Seq2) = split;
if(defined($bow1{$ID2})){#IDs Match
if($bow1{$ID2} eq $Seq2){
#both match so remove from the hash to avoid looking fo
+r a correct one later
delete $bow1{$ID2};
}else{
#id's dont match
print "IDs exist but dont match ID:$ID2:Seq1:$bow1{$ID2}:Seq2:$
+Seq2:\n";
}
}else{
#id not in list 1
print "ID only in file 2 ID:$ID2:$Seq1\n"
}
}
close FILE2
#run through any remaing list one items that werent matched
while((my $key,my $value) = each %bow1){
print "ID only in file 1 ID:$key:Seq:$value:\n";
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|