In this case I'd use a variable $index (or $idx ) for arrays and for other loops an auto-incremented $counter++
The loop may run longer due to the increment operation, but
print ' ' x $indentation if $idx == 0;
is always readable and can also be extended for last line ( $idx == $#array ) or some modulo intervals
Mr Muskrat already showed you how each can be used to get index and value in one go.
Please be aware that your flag-approach can be better readable in other cases.
Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!
In reply to Re: Easiest way to do something only on first iteration of loop
by LanX
in thread Easiest way to do something only on first iteration of loop
by ibm1620
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |