...or simply...
print "'F' is at index: $_\n" for grep { $text[$_] eq 'F' } 0 .. $#text;
List::MoreUtils provides a sugary alternative, "indexes":
use List::MoreUtils qw( indexes ); # ... print "'F' is at index: $_\n" for indexes { $_ eq 'F' } @text;
This is a case where I prefer grep because what it's doing isn't unclear or awkward enough to justify the module (imho).
Dave
In reply to Re: Index number repeating in for loop
by davido
in thread Index number repeating in for loop
by DW10
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |