Hi Monks,
I have a hash and trying to get the keys and values, but not getting the expected output doing somewhere wrong
#!/usr/bin/perl -w use strict; use warnings; use Data::Dumper; my %hash = { 'debt-1' => { 'debt_id' => 10, 'mobile' => 11, 'address1' => 12 }, 'dedt-2' => { 'debt_id' => 20, 'mobile' => 21, 'address1' => 22 }, 'debt-3' => { 'debt_id' => 30, 'mobile' => 31, 'address1' => 32 }, 'debt-4' => { 'debt_id' => 40, 'mobile' => 41, 'address1' => 42 } };
print "\n---------------------Top 4 ---------------------\n"; print Dumper \%hash; print "\n---------------------Top 5 ---------------------\n";
When I tried print the dump, i get
---------------------Top 4 --------------------- $VAR1 = { 'HASH(0x7fc9b5936d80)' => undef }; ---------------------Top 5 ---------------------
-------------2-------------
my $cnt = 1; while ( my ($name, $ITEM) = each %hash ){ print "[ $cnt ] --- $name \n"; # print Dumper $ITEM; my $in_cnt = 1; while ( my ($item, $value) = each %{$ITEM}) { print "[ $cnt ] --- [ $in_cnt ] --- $item => $value \n"; # print Dumper $item; $in_cnt++; } $cnt++; }
And when i tried to extract the keys and values, i get
[ 1 ] --- HASH(0x7fc9b5936d80) Argument "HASH(0x7fc9b5936d80)"
Please give me directions to get the keys and values from the above hash.
Thanks in advanced
In reply to Print values and keys from hash of hashes. by Sami_R
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |