Of course the current implementation already is an iterator – if you need several, you can just instantiate any number of Array::AsHash objects on the same underlying array.
If Ovid prefers this, he could facilitate it by providing a ->copy constructor which resets the iterator in the new instance, for use by code which has no access to the original underlying array.
However, assuming the class does not contain more methods, I wonder why an object is at all necessary for this. I’d just bake closure directly:
my $each = make_array_iterator \@array; while( my( $idx, $val ) = $each->() ) { # ... }
That seems far more natural to me.
Makeshifts last the longest.
In reply to Re^2: Caller, caller, wherefore art thou, caller?
by Aristotle
in thread Caller, caller, wherefore art thou, caller?
by Ovid
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |