Keep It Simple, Stupid | |
PerlMonks |
Re: How to get the key - value names from a hashby davido (Cardinal) |
on Nov 29, 2019 at 22:35 UTC ( [id://11109460]=note: print w/replies, xml ) | Need Help?? |
Line 61 and 81 in your pasted code are both blank lines. The actual line numbers you are seeing warning messages on are either probably 62, and 82 of what you posted. "How to get the key - value names from a hash":
The warnings you are seeing on line 62 of the code you posted, and line 82: On line 82 you reference $average{0}. That means that $avg must, at least one time, have equated to zero. Put a print statement like this: print "avg: $avg\n", "\$avg is exactly 0:", ($avg == 0 ? " yes" : " no"), "\n"; on the line immediately following where $avg gets defined. I'll bet you don't see any exact zeros. On line 62 you are printing "$odd_even{0}", but nothing ever puts an element names '0' in your %odd_even hash. Why do you think that after creating a hash key that looks like "9 9" you could then expect to be able to print a hash element named 0? I think that spending 30 minutes reading perlintro and possibly another ten minutes skimming perldata would clear things up. As I've learned other languages I've often wished those languages had such good documentation. Dave
In Section
Seekers of Perl Wisdom
|
|