Solved

comparing hashes with different keys

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…

749 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