The problem is people have a bad habit of forgetting to reset the iterator, and heaven help you if the general routine calls back out to uncontrolled code from inside the loop. Can you say "infinite loop"? :-)
---
$world=~s/war/peace/g
| [reply] |
| [reply] |
I think the problem is not with iterators as such, as much as with the fact that the scope and workings of this particular iterator are so non-obvious. In other words, it's the "magic" the bites here, IMO, not the iterator. I posted a hash iterator class some months ago that lets one create multiple simultaneous lexically-scoped iterators on any hash, but somehow it feels like overkill for most situations. Maybe this is a facility that should be built-in.
| [reply] |
Well, I'd argue that any program for which the difference between a keys-based walk and an each-based walk is significant shouldn't be using hashes that large, not with the arrival of things like DBD::SQLite or other cheap databases.
Yes, it mattered when Perl was running on 10Mhz 1Megabyte machines, and databases were tough, so a DBM hash was a cool thing. Those are long gone. {grin}
| [reply] |
Oh sure. But you don't always live in an ideal world. Sometimes, the data format is given, and Perl (and the programmer) just has to adapt. That's what Perl is supposed to be good at.
| [reply] |