Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
As Herkum pointed out above, you are making this too complicated. You said yourself:
What I want to do is check if a VALUE in Ahash is also in Bhash (or a line in File1 is also in File2).

So just using whole lines from each file as the hash keys (like Herkum does) is the thing to do. In case the same string can occur multiple times in one file -- and in case it's important to keep track of how many times it occurs -- here's a simple variation on his approach to handle that:

my %strings; while (<FILE1>) { chomp; $string{$_} .= '1'; # if same data appears three times, hash valu +e is "111"; } while (<FILE2>) { chomp; $string{$_} .= '2'; # same as above, but with "2" instead of "1" } # get hash keys (lines) that occur in both files: my @common = grep { $strings{$_} =~ /12/ } sort keys %strings; # report findings: for my $key ( @common ) { my ( $n1, $n2 ) = ( $strings{$key} =~ /(1+)(2+)/ ); printf("%s found %d times in file1, %d times in file2\n", $key, length($n1), length($n2)); } # you can also pick out strings unique to file1 (/1$/) # and/or strings unique to file2 (/^2/), along with their # frequency of occurrence. This also scales fairly well to # handling three or more files.

In reply to Re: Compare Values in HoH by graff
in thread Compare Values in HoH by AcidHawk

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others chanting in the Monastery: (7)
    As of 2014-12-25 11:29 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (160 votes), past polls