![]() |
|
go ahead... be a heretic | |
PerlMonks |
Re^4: keys and values order on a hashby Somni (Friar) |
on Jul 11, 2011 at 18:50 UTC ( #913751=note: print w/replies, xml ) | Need Help?? |
Indeed, you can insert a keys call prior to using 'each' in every instance, presuming you're not already in the middle of an 'each' on that hash already, and thereby reset the iterator mid-stream:
Admittedly, this example is a bit contrived, but it's generally unexpected that your loop becomes infinite just from simple calls that don't appear to modify the hash. The workaround is obvious, if restricting: don't pass the hashref to any functions (including functions with prototypes that auto-enreference it). It's even worse if the hash is global; you essentially can't call any functions, for fear that, somewhere in the call chain, something will call 'keys' on the hash. In my opinion, it's too many caveats to make 'each' very useful.
In Section
Seekers of Perl Wisdom
|
|