![]() |
|
No such thing as a small change | |
PerlMonks |
Re: hash and array mismatchby BrowserUk (Patriarch) |
on May 08, 2007 at 02:05 UTC ( #614080=note: print w/replies, xml ) | Need Help?? |
A hash cannot have duplicate keys, whereas an array can. Hence, the key POSITION NAME is given a value of 9. but then 6 lines later on, the value associated with that key gets overwritten with the value 15. And the key RESULT is initially set to the value 10, but the later overwritten with the value 16. And so on for all the other missing values. What you can do about it depends upon what you want to do with the hash afterwards. It maybe as simple as reversing the keys and values. The line number (position) will always be unique, so you could use that as the key and the text as the value, but that makes it little more useful than the array. Perhaps what you want is
Which will accumulate an array of positions associated with each value. It would dump something like
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
In Section
Seekers of Perl Wisdom
|
|