Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Difference Between Two hash

by Nansh (Acolyte)
on Feb 07, 2017 at 13:18 UTC ( [id://1181288]=perlquestion: print w/replies, xml ) Need Help??

Nansh has asked for the wisdom of the Perl Monks concerning the following question:

Can any one tell me How to find the difference between two hash without using "Hash::diff". I need to find difference between both keys and values. If Key is not present in one hash it need to show which key is not present. If value is not present then it should show in which key what value is not present. Note: I used $hash1{key}=@arr1; and $hash2{key}=@arr2;

Replies are listed 'Best First'.
Re: Difference Between Two hash
by GotToBTru (Prior) on Feb 07, 2017 at 13:31 UTC

    This homework is intended to teach you how to navigate inside hashes. I would read the tutorial here and perldata.

    There are built in functions in Perl for retrieving the keys and values of a hash. You'll be using those as well as the direct form of access. Show us what you have for code, and we can offer suggestions. It won't help you for us to do your homework for you, especially on fundamentals like this.

    But God demonstrates His own love toward us, in that while we were yet sinners, Christ died for us. Romans 5:8 (NASB)

Re: Difference Between Two hash
by Corion (Patriarch) on Feb 07, 2017 at 13:27 UTC

    If you don't want to use some arbitrary module, you will have to write the code yourself.

    You already seem to have some algorithm for finding the difference between two hashes, so you only need to encode that in Perl for a first start.

    As you don't show us which parts you already have written and where you have problems, I can only give you general advice. This means you should look at keys and exists.

Re: Difference Between Two hash
by haukex (Archbishop) on Feb 07, 2017 at 14:14 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1181288]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-05-26 18:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found