sub countt{
...
my @arraystr =split(//,$string);#split the string acc. to each al
+phabet and pass it to the array.
foreach my $alpha($string){
if ($alpha =~ /t/i){ # if 't' is found
$count++; #increment the count
return $count; #
}
}
If you want to stick to your own approach, I see two issues with your original code:
- you create an array, but don't use it ... maybe you want to use arraystr in your loop
- inside the loop, you have the return; this ends your subroutine before all elements have been processed; you will want to move the return behind the loop...
HTH, Rata