changma_ha has asked for the wisdom of the Perl Monks concerning the following question:
Hi all..I got struck in a problem. I have wrote a code where using a subroutine i have to count the occurrence of "t". Here is my code
plz help me out.. thanx in advance#! /usr/bin/perl use strict; use warnings; sub countt{ my $string =<STDIN>; my $count = 0; $string =~ s/\s*\n//g; # removes the spaces and newline character. 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; } } } #my @list = qw (here is the man in the rain); print &countt;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Getting the count of a particular alphabet using subroutine
by suhailck (Friar) on Aug 06, 2010 at 06:08 UTC | |
by changma_ha (Sexton) on Aug 06, 2010 at 06:28 UTC | |
|
Re: Getting the count of a particular alphabet using subroutine
by Ratazong (Monsignor) on Aug 06, 2010 at 06:59 UTC | |
by k_manimuthu (Monk) on Aug 06, 2010 at 08:01 UTC | |
by changma_ha (Sexton) on Aug 06, 2010 at 10:01 UTC | |
|
Re: Getting the count of a particular alphabet using subroutine
by toolic (Bishop) on Aug 06, 2010 at 12:03 UTC | |
|
Re: Getting the count of a particular alphabet using subroutine
by murugu (Curate) on Aug 06, 2010 at 06:04 UTC | |
|
Re: Getting the count of a particular alphabet using subroutine
by Anonymous Monk on Aug 06, 2010 at 14:47 UTC |