CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Print An Array of Hashes

 



SuzuBell
New User

Mar 20, 2013, 9:06 PM

Post #1 of 4 (273 views)
Print An Array of Hashes Can't Post

Hello:

I want to print an array of 20 hashes. Each hash has 2 types of keys.

I am not too particular about how to print. I am just doing this to check that the array has all 20 hashes working, where the correct value is associated with the correct two keys. One way I might like to check the array (if possible) is to print the values from each hash of the array (That is, check that hash1 has the correct values with the correct key1s and key2s, then check that hash2 has the correct values with the correct key1s and key2s, ....).

The values of all hashes are all strings or empty strings. This is the general idea of my code:


sub getArrayHash{
$hash1s->{$key1}->{$key2} = $hash1;
$hash2s->{$key1}->{$key2} = $hash2;
$hash3s->{$key1}->{$key2} = $hash3;
.
.
.
$hash20s->{$key1}->{$key2} = $hash20;

push( @hash_array, $hash1s, $hash2s, $hash3s, ..., $hash20s);

return \@hash_array;
}


So, any ideas on how to check that my hash_array has the correct values? Thank you in advance!


FishMonger
Veteran / Moderator

Mar 20, 2013, 9:15 PM

Post #2 of 4 (272 views)
Re: [SuzuBell] Print An Array of Hashes [In reply to] Can't Post


Code
use Data::Dumper; 

my $AoH = sub getArrayHash();
print Dumper $AoH;



Laurent_R
Enthusiast / Moderator

Mar 21, 2013, 4:52 PM

Post #3 of 4 (260 views)
Re: [FishMonger] Print An Array of Hashes [In reply to] Can't Post

Yes, Data::Dumper is the answer.

An alternative I am using very often is to use the 'x' command under the debugger.


FishMonger
Veteran / Moderator

Mar 21, 2013, 5:32 PM

Post #4 of 4 (256 views)
Re: [FishMonger] Print An Array of Hashes [In reply to] Can't Post

I just noticed that I had a copy/paste error.

this:

Code
my $AoH = sub getArrayHash();


should have been:

Code
my $AoH = getArrayHash();


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives