in reply to Getting the count of a particular alphabet using subroutine

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:

HTH, Rata

Replies are listed 'Best First'.
Re^2: Getting the count of a particular alphabet using subroutine
by k_manimuthu (Monk) on Aug 06, 2010 at 08:01 UTC

    And another one way

    $string='Put your text'; $count++ while($string=~ m{t}g);
Re^2: Getting the count of a particular alphabet using subroutine
by changma_ha (Sexton) on Aug 06, 2010 at 10:01 UTC

    Thanx Ratazong..... i made a silly mistakes while writing by not passing an array...now my probs is solved.