robertw has asked for the wisdom of the Perl Monks concerning the following question:
Dear perlmonks, I have an array in a hash in a hash but when i dump the hash i only get this 54/128? What does this mean and how can I resolve this error? Thank you so much in advance:)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: perl strange hash value
by CountZero (Bishop) on Sep 08, 2012 at 14:47 UTC | |
To get the contents of a hash use keys, values or each. Or have a look at Data::Dumper. Update: Thanks Davido for pointing out that I missed scalar in my example. CountZero A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James My blog: Imperial Deltronics | [reply] [d/l] [select] |
by robertw (Sexton) on Sep 08, 2012 at 15:13 UTC | |
Underneath I first print my hash, then i print a hash stored in a the hash (aegon) but i cant acces the array like this $totalhistoricalhash{Aegon}{$Aegon1} because that prints nothing, and $totalhistoricalhash{Aegon} prints only 11/16. I dont get how to access one of these variables because I am doing something wrong:S. I dumper both by the with perl dumper(/)
| [reply] [d/l] |
|
Re: perl strange hash value
by Jim (Curate) on Sep 08, 2012 at 15:16 UTC | |
Study perldoc perldsc. Pay particular attention to Access and Printing of an ARRAY OF HASHES and Access and Printing of a HASH OF HASHES. Also, next time, for more helpful help, post the Perl code you're having difficulty with (just the relevant part). | [reply] |
|
Re: perl strange hash value
by davido (Cardinal) on Sep 08, 2012 at 17:09 UTC | |
When you look at a hash in scalar context you get a rather useless fraction that describes how the buckets are allocated and being used. When you look at a hash in list context, you get a raw dump of key, value, key, value, which is usually what you want.
Dave | [reply] [d/l] |
|
Re: perl strange hash value
by philiprbrenan (Monk) on Sep 08, 2012 at 16:50 UTC | |
I think somewhere you must have assigned the result of scalar %hash instead of \%hash. I have taken the liberty of restructuring your code slightly to illuminate the reference I believe you are trying to make:
Produces:
| [reply] [d/l] [select] |
|
Re: perl strange hash value
by kcott (Archbishop) on Sep 08, 2012 at 16:52 UTC | |
As you've shown no code, this is just a guess. I suspect you've written something like:
when you really wanted something more like:
Note the assignment of %y in the first example and \%y in the second example. For a better answer, follow the guidelines in How do I post a question effectively? -- Ken | [reply] [d/l] [select] |
|
Re: perl strange hash value
by Rudolf (Pilgrim) on Sep 08, 2012 at 16:14 UTC | |
The n/n output you are seeing is how many buckets are empty if you think of the hash like buckets that is. | [reply] |