in reply to Re^3: Finding target unspecified value
in thread Finding target unspecified value

I need to rework this code again. The code works in finding a number at the index point. What I didn't account for is multiple accounts of the same number. So if my numbers were 10 22 16 13 22 19, and my target number is 22 it would say the last occurrence of 22 is at index 1, and it should be index 4.

Replies are listed 'Best First'.
Re^5: Finding target unspecified value
by Lennotoecom (Pilgrim) on Oct 20, 2013 at 23:42 UTC
    this:
    @a = (12, 18, 56, 76, 99); $in = <STDIN>; for(0..$#a){ $i = $_ if $in == $a[$_]; } $i == 0 ? print "not found\n" : print "found at $i\n";