in reply to Re^2: Finding target unspecified value
in thread Finding target unspecified value
So the code runs, and asks for a target to search for. If its a number displayed, and I enter that number it tells me which index it is. If I enter a number that is not displayed I should see - Target is not found. So for instance the number 100 is not displayed. I see - The last occurrence of 100 is at index -1.print "Enter a target value to search for:"; use List::MoreUtils; chomp (my $search = <STDIN>); my $index = List::MoreUtils::first_index {$_ eq $search} @array; if ($search) { print "The last occurence of $search is at index: $index\n"; } else { print "Target is not found\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Finding target unspecified value
by kcott (Archbishop) on Oct 21, 2013 at 05:58 UTC | |
|
Re^4: Finding target unspecified value
by Lennotoecom (Pilgrim) on Oct 20, 2013 at 23:23 UTC | |
|
Re^4: Finding target unspecified value
by Latnam (Novice) on Oct 20, 2013 at 23:39 UTC | |
by Lennotoecom (Pilgrim) on Oct 20, 2013 at 23:42 UTC |