?
Solved

comparing hashes with different keys

Posted on 2007-11-15
2
Medium Priority
?
207 Views
Last Modified: 2010-03-05
I have two hashes. One of the hash has a composite key acct number, date and currency while the other is a single key with just the acct number. I need to compare the hashes with the same acct numbers. could you please advise?
0
Comment
Question by:saibsk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 39

Expert Comment

by:Adam314
ID: 20291817
For the first hash with key,acct,date - create another version of this with just acct number as the key.
0
 
LVL 40

Accepted Solution

by:
evilrix earned 1500 total points
ID: 20292248
>> create another version of this with just acct number as the key.
What if there are duplicate acct numbers? Presumably this is why they are composite keys?
I presume you want to compare values?

Parse the hash with the composite keys.
Break the key up using split, for example to obtain the acct number
Get the value out of the hash for the composite key
Get the value out of the hash with acct as the key
Compare values.

Something like...

foreach my $compokey (keys %compohash)
{
    my $acctkey = split /-/, $compokey;
    print "match $compokey\n" if $compohash{$compokey} == $accthash{$acctkey};
}

foreach my $compokey (keys %compohash)
{
    my $acctkey = split /-/, $compokey;
    print "match $compokey\n" if $compohash{$compokey} == $accthash{$acctkey};
}

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question