in reply to Easiest way to do something only on first iteration of loop
Several good ways to do this have already been mentioned for Perl 5.
I'll also note that your question was one of the many things addressed in Perl6.
Perl 6 added an explicit phaser for first loop invocation you can use like this:
for @arr -> $line { FIRST { print ' ' xx $indentation }; say $line; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Easiest way to do something only on first iteration of loop
by ibm1620 (Hermit) on May 09, 2016 at 14:43 UTC | |
by Anonymous Monk on May 09, 2016 at 17:41 UTC |