Solved

comparing hashes with different keys

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Title # Comments Views Activity
how to extract data from a table into a fixed length file 10 60
pipe to sed or perl, please help 5 130
Perl string filter 5 81
Call Shell Script from Perl Script 6 134
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 …
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…
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…

838 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