tangent.gardner has asked for the wisdom of the Perl Monks concerning the following question:
This works ok for a few iterations of the outer loop, but after about 200, the foreach seems to ignore all but a couple of %timings members.for (;;) { foreach my $item (sort (keys %timings)) { do_stuff(); # changes data, not keys, no deletes } }
|
|---|
| Replies are listed 'Best First'. | |||
|---|---|---|---|
|
Re: looping through hash of hashes
by Corion (Patriarch) on Dec 03, 2015 at 12:28 UTC | |||
Most likely, %timings does not contain what you think it does. Maybe inspect it before every iteration:
| [reply] [d/l] [select] | ||
by tangent.gardner (Initiate) on Dec 04, 2015 at 06:28 UTC | |||
And here is the data file: My original assumption about the number of outer iterations is wrong. If the STOP vales are all the same everything works fine. Things go funny if they are different. Obviously there is something wrong with my logic, or my understanding of hashes. | [reply] [d/l] [select] | ||
by choroba (Cardinal) on Dec 04, 2015 at 13:02 UTC | |||
| [reply] [d/l] [select] | ||
by tangent.gardner (Initiate) on Dec 08, 2015 at 07:11 UTC | |||
|
Re: looping through hash of hashes
by Athanasius (Archbishop) on Dec 05, 2015 at 03:38 UTC | |||
Hello tangent.gardner, and welcome to the Monastery! choroba++ has identified the logic error in your script. I just want to point out a few aspects of your code which could be improved. Hope that helps,
| [reply] [d/l] [select] | ||
|
Re: looping through hash of hashes
by AnomalousMonk (Archbishop) on Dec 05, 2015 at 16:11 UTC | |||
Further to choroba's point about warnings and Athanasius's point 1 about prototypes (++both): Using warnings would have alerted you the fact that there was more than one unkosher thing about the way you were using prototypes. Without warnings: And with:
Give a man a fish: <%-{-{-{-< | [reply] [d/l] [select] | ||
by Anonymous Monk on Dec 12, 2015 at 21:30 UTC | |||
| [reply] | ||