Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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"; }

In reply to Re: how to compare two hashes with perl? by colwellj
in thread how to compare two hashes with perl? by FluffyBunny

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (7)
As of 2024-04-18 03:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found