in reply to Re^3: Finding the index of a specific element in an array.
in thread Finding the index of a specific element in an array.
for my $i (0 .. $#array) { next unless $array[$i] == 7; say "The index is $i"; }
You may quibble that the use of $#array is itself an artifact of the method I've chosen to solve the problem (and I can agree), but there's less synthetic code in this version. Certainly there's iteration and incrementing, but when Perl handles that and the programmer doesn't have to, there's less synthetic code.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Finding the index of a specific element in an array.
by BrowserUk (Patriarch) on Jan 25, 2012 at 02:41 UTC | |
by chromatic (Archbishop) on Jan 25, 2012 at 19:43 UTC | |
|
Re^5: Finding the index of a specific element in an array.
by JavaFan (Canon) on Jan 25, 2012 at 10:41 UTC | |
by chromatic (Archbishop) on Jan 25, 2012 at 19:44 UTC | |
by JavaFan (Canon) on Jan 25, 2012 at 20:55 UTC | |
by chromatic (Archbishop) on Jan 25, 2012 at 21:14 UTC |