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

What is cpan ? What are the modules coming under this?

685


Explain lists ?

695


What is the use of 'ne' operator?

685


Suppose an array contains @arraycontent=(‘ab’, ‘cd’, ‘ef’, ‘gh’). How to print all the contents of the given array?

762


How many data types are there in perl?

732


For a situation in programming, how can you determine that Perl is a suitable?

658


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

636


What does this symbol mean '->'?

704


What is hash?

708


Why do you use Perl?

745


What are the different types of perl operators?

726


Write syntax to use grep function?

723


how to create a flat file database as shown below s.no name age city phone 0 hema 22 Calcutta 4312542 1 hema 21 Bangalore 2344345 2 ganesh 25 delhi 2445454 3 kartik 45 pune 4312121 4 santosh 25 Hyderabad 2254231 5 kumar 25 mysore 2344567 6 gita 34 mangalore 6532123 7 gita 32 pune 2213456 Q1.print the details of the person who r from bangalore q2.Replace the city name managlore to pune q3.prints no of person having name gita and hema q4.print how many are of age 25.

1841


How do you set environment variables in perl?

737


You want to add two arrays together. How would you do that?

644