in reply to Re: Determine first element in foreach
in thread Determine first element in foreach
Even when you want to loop over the indexes, you can still use a foreach-style loop:
foreach my $i (0 .. $#mylist) { say "first element" if ( $i == 0 ); }
foreach-style loops are generally a better idea that C-style for loops. They're clearer; more declarative. It's harder to introduce an off-by-one error, and easier to spot a mistake.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Determine first element in foreach
by AnomalousMonk (Archbishop) on Aug 04, 2014 at 20:45 UTC | |
by tobyink (Canon) on Aug 05, 2014 at 07:17 UTC |