http://www.perlmonks.org?node_id=1041355


in reply to Index number repeating in for loop

Two quick solutions, one the same as AnomalousMonk's but I'd already run it so I might as well post it!

$ perl -Mstrict -Mwarnings -E ' my $want = q{F}; my @text = q{A} .. q{J}; for my $index ( 0 .. $#text ) { next unless $text[ $index ] eq $want; say qq{$want at $index}; last; } my $index; for my $elem ( @text ) { do { $index ++; next; } unless $elem eq $want; say qq{$want at $index}; last; }' F at 5 F at 5 $

Cheers,

JohnGG