Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: Comparing two hashes

by dwm042 (Priest)
on Apr 01, 2010 at 21:08 UTC ( #832386=note: print w/replies, xml ) Need Help??

in reply to Comparing two hashes

As other monks have pointed out, the question is a little vague. If what you're trying to do is compare elements in one hash with elements in another hash, and the key values do not matter, you could use code something like this:
#!/usr/bin/perl use warnings; use strict; my %giant = ( fee => 'fi', fo => 'fum', I => 'smell' ); my %mouse = ( eeeny => 'meeny', miny => 'mo', nose => 'smell' ); my $out = "giant\{%s\} equals mouse\{%s\}\n"; for my $g ( sort keys %giant ) { for my $m ( sort keys %mouse ) { printf $out, $g, $m if ( $giant{$g} eq $mouse{$m} ); } }

Replies are listed 'Best First'.
Re^2: Comparing two hashes
by ruzam (Curate) on Apr 02, 2010 at 02:06 UTC
      Actually, that's what I intended to do, ruzam. And that's what I said I was going to do. One example, of one possible interpretation of the OP's question, was all I wanted to provide.
        My bad, sorry. You're absolutely right and I should have read your response more carefully. I'm afraid I got caught up in the code example without paying attention to the lead in.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://832386]
[LanX]: marto: btw is Glasgow a safe place for yapc? heard it has one of the highest murder rates in western Europe
[LanX]: ... oh Amsterdam is worse. ..
[marto]: only when I'm bored
[LanX]: we should certainly avoid Amsterdam! ! !
[marto]: kidding. The area in question isn't great. I'd no idea these facilities existed in that part of town.
LanX vile place ...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (13)
As of 2017-12-14 15:42 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (396 votes). Check out past polls.