Hello BioLion,

Basically I followed your code,
use warnings; use strict; my %bow1 = (); my $file1 = shift; open (FILE1, "$file1"); # Open first file while (<FILE1>) { my ($ID1, undef, undef, undef, $Seq1) = split; $bow1{$ID1} = $ID1; $bow1{$Seq1} = $Seq1; print STDERR "$bow1{$ID1}\t$bow1{$Seq1}\n"; } close FILE1; my %bow2 = (); my $file2 = shift; open (FILE2, "$file2"); # Open second file while (<FILE2>) { my ($ID2, undef, undef, undef, $Seq2) = split; $bow2{$ID2} = $ID2; $bow2{$Seq2} = $Seq2; print STDERR "$bow2{$ID2}\t$bow2{$Seq2}\n"; } close FILE2; foreach my $ID1 (keys %bow1){ # can use (sort keys %hash) to put items + in a specified order if ( exists $bow2{$ID2} ){ if ( $bow1{$ID1} eq $bow2{$ID2} ){ ## id and sequence are stored as key value pairs print "$bow1{$ID1} exists in $file1 and $file2 and the sequen +ces match $bow1{$Seq1} $bow2{$Seq2} \n"; } else{ print "$bow1{$ID1} exists in $file1 and $file2 but sequences D +O NOT match $bow1{$Seq1} $bow2{$Seq2} \n"; } } else { print "$bow1{$ID1} only exists in $file1 .\n"; } } exit;
However I get some errors
Global symbol "$ID2" requires explicit package name at /home/choia2/sc +ripts/BowtieCompare.pl line 50. Global symbol "$ID2" requires explicit package name at /home/choia2/sc +ripts/BowtieCompare.pl line 51. Global symbol "$Seq1" requires explicit package name at /home/choia2/s +cripts/BowtieCompare.pl line 53. Global symbol "$Seq2" requires explicit package name at /home/choia2/s +cripts/BowtieCompare.pl line 53. Global symbol "$Seq1" requires explicit package name at /home/choia2/s +cripts/BowtieCompare.pl line 56. Global symbol "$Seq2" requires explicit package name at /home/choia2/s +cripts/BowtieCompare.pl line 56. Execution of /home/choia2/scripts/BowtieCompare.pl aborted due to comp +ilation errors.

Basically the foreach loop.. I never used hash for other programming languages (I wasn't professional though) but this hash concept is confusing.. could you help me one more time? >.<


In reply to Re^4: how to compare two hashes with perl? by FluffyBunny
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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.