in reply to Automatic Loop Counter not in perl
I have always felt the lack of a special variable (call it $LOOPCOUNTER), which starts from 0, and counts the number of times the innermost while, for, etc... has run.
By your definition 'the number of times the innermost ... has run', I'd expect much different behaviour than what you're describing:
There would only be one such variable, so you could only use it in the innermost loop. Any loop would reset it to zero when starting, and increment it at each iteration.
You see, you specifically call out the 'innermost' loop, but I frequently have nested loops, and if I'm interested in the 'number of times the innermost (loop) has been called', I'm interested in the TOTAL number of times it's been called:
my $count = 0; foreach my $arrayRef ( @twoDimArray ) { foreach my $item ( @$arrayRef ) { $count++; } }
I'd also be concerned with the 'you could only use it in the innermost loop'. What happens if I use it, in a rather long loop, and someone comes in and adds a line that uses 'foreach' somewhere within the loop? Would it break my code? If so, it's not worth taking the risk of using it.
How would a subroutine that contains a loop affect the restriction on only innermost loops?
...
Personally, if I were to ever use something like this, I would want :
|
|---|