Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^2: Perl Array of Hashes

by abhay180 (Acolyte)
on Jul 27, 2009 at 05:55 UTC ( #783443=note: print w/ replies, xml ) Need Help??


in reply to Re: Perl Array of Hashes
in thread Perl Array of Hashes

Hello, Thnaks a ton for all ur suggestions. I wanted to do little more here...

my $k=0,$str=""; for(my $i=0; $i<4;$i+=1) { @entry=undef; for my $j (0..7) { $h{"BUCK_$j"} = $bucket[$k+$j]; push @entry,\%h; } $hash_table[$i] = { ENTRY => [@entry]}; $k+=8; } #end of for i for(my $i=0; $i<4;$i+=1) { print "ENTRY-0-BUCK-0::", $hash_table[$i]->{ENTRY}->{BUCK_0}, "\n"; }
The print of "ENTRY-0-BUCK-0" doesnt work....what is that i am doing wrong here?


Comment on Re^2: Perl Array of Hashes
Download Code
Re^3: Perl Array of Hashes
by mzedeler (Pilgrim) on Jul 27, 2009 at 07:19 UTC

    Did you use warnings and use strict when you ran the code?

    But that aside, you are doing some strange things:

    my $k=0,$str=""; for(my $i=0; $i<4;$i+=1) { @entry=undef; for my $j (0..7) { $h{"BUCK_$j"} = $bucket[$k+$j]; push @entry,\%h; }

    The loop above will add 8 identical references to %h to @entry.

    $hash_table[$i] = { ENTRY => [@entry]}; $k+=8; } #end of for i for(my $i=0; $i<4;$i+=1) { print "ENTRY-0-BUCK-0::", $hash_table[$i]->{ENTRY}->{BUCK_0}, "\n";

    You can't address $hash_table like that since it is an array of hash references containing just the key ENTRY (which is a warning sign) that has the value array reference containing hash references.

    }

    Did you try following the advice and tried Data::Dumper on, say, (updated) @hash_table?

      Yes, By using Dumper,I was able to correctly construct the data-structure i needed. Thanks a lot for all ur help.
      Yes, with Dumper, i am able to generate data-structure of my choice. Thanks a ton.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://783443]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2014-07-23 03:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (132 votes), past polls