in reply to Re^2: Hash w/ multiple values + merging
in thread Hash w/ multiple values + merging

what you are seeing is a reference to the data held under that key, so "ARRAY(0x183d294)" for example is the location where the value associated with "ATA" is stored, to access that value you need to dereference it using the appropriate dereferencers, read the links at the bottom of my previous reply.

Since the reference type in this case is of an ARRAY something like "@$hash{ATA}}" would show you the values associated with "ATA", to access them one at a time you can specify indices like you do any regular arrays; $hash{ATA}[0] would print the first element of the anonymous array associated to the key "ATA"..

The module Data::Dumper would show you the data structures stringified so that you could judge if they look like you expected them before proceeding any further...

#ADD this to the previous code... use Data::Dumper; print Data::Dumper->Dump([\%hash1],['FIRST HASH']),"\n"; print Data::Dumper->Dump([\%hash2],['SECOND HASH']),"\n"; print Data::Dumper->Dump([\%hash3],['MERGED HASH']),"\n";

Note also that there can be more than one way to do it which would become clearer when you start dealing with more complex data structures..


Excellence is an Endeavor of Persistence. Chance Favors a Prepared Mind.

Replies are listed 'Best First'.
Re^4: Hash w/ multiple values + merging
by sophix (Sexton) on Feb 07, 2010 at 23:04 UTC
    Yes, it worked just fine. Thank you, biohisham! Could you also please guide me for the merge operation? What I have in mind is the following: 1. Start iterating over the keys of hash1 2. Check if any of these keys match with the keys of hash2 3. if matched, push values %hash2 into values%hash1 Is this the right way to do it?
      That way is correct, I don't know however if it is the best way out there so I am not sure if it is computationally expensive or optimal... Anyways, take a look at the code I posted once again for I've already added this information using the same idea !!!...