in reply to Re^4: why each/keys/values can't work on slice? (updated)
in thread why each/keys/values can't work on slice?
I don't understand why every array has to have only one iterator
First of all, it's one more than needed.
for my $ind ( 0 .. $#bb ) { say "ind is $ind"; }
And to answer your question, it's the maximum you can have. If you want multiple iterators, they necessarily have to be external to the array.
For example, in C#, you have to create an external iterator.
using ( var enumerator = list.GetEnumerator() ) { while ( enumerator.MoveNext() ) { var item = emumerator.current; // ... } }
Nothing stops you from doing the same in Perl.
Now, C# does have syntactical sugar that makes this cleaner.
for ( var item in list ) { // ... }
Again, nothing stops you from doing the same in Perl.
If no one's done it, I guess it's not that useful. (I'm not saying noone's done it. I have no idea.)
|
|---|