[ create a new paste ] login | about

Link: http://codepad.org/FHaOiLuX    [ raw code | output | fork ]

skeletonkey - Perl, pasted on Sep 28:
1
2
3
4
5
6
7
8
9
10
@items = qw(1 2 3 4 5 6 7 8 9);

$x = 6;
$i = -1;
$index = 0;
foreach (@items) {
    $i = $index, last if $x eq $items[$index];
    $index++;
}
print "$x was found at $i (-1 means it wasn't found)\n";


Output:
1
6 was found at 5 (-1 means it wasn't found)


Create a new paste based on this one


Comments: