Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

How to count no of occurrence of a unique patterns in perl?

Answer Posted / perllearner

my %hshUniq;

my $testString = "This is the programme to check the count of unique values present in this text This is the programme to check";
my @arrList = split (" ",$testString);

foreach (@arrList);
{
chomp($_);
if ( exist %hshUniq{$_})
{
my $count = $hshUniq{$_};
$hshUniq{$_} = $count++;
}else
{
$hshUniq{$_} = 1;
}
}

while (($key,$value) = each(%hshUniq))
{
print "The unique character $key count in the string is $value
";
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain goto label?

909


What does `new $cur->{LINK}' do? (Assume the current package has no new() function of its own.)

931


How to prevent file truncation in perl?

1004


Give an example of the -i and 0s option usage.

891


What are the two ways to get private values inside a subroutine?

891


Explain goto expr?

866


In CPAN module, name an instance you use.

951


How do I sort a hash by the hash value?

917


How to code in perl to implement the tail function in unix?

926


Differentiate between arrays and list in perl.

983


Difference between the variables in which chomp function work ?

1060


Explain returning values from subroutines?

939


What do you mean by context of a subroutine?

972


How can we create perl programs in unix, windows nt, macintosh and os/2 ?

879


What is warn function in perl?

947