Solved

comparing hashes with different keys

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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 …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

757 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

20 Experts available now in Live!

Get 1:1 Help Now