[ create a new paste ] login | about

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

Perl, pasted on Jul 8:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use warnings;

my $string = "4 2 6 7";
my $i = 6; #use any value of $i

my @x = split / /, $string;
my $count = 0;

foreach (@x)
{
if($_ == $i) 
{ 
print "matched at position $count"; die $!;
}
$count++;
}
print "integer doesn't found in string";


Output:
1
2
Died at line 13.
matched at position 2


Create a new paste based on this one


Comments: