Solved

comparing hashes with different keys

Posted on 2007-11-15
2
199 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
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 500 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

813 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now