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
What does a die() function do in perl?
Give an example of using the -n and -p option.
How to merge two arrays in perl?
What is the difference between use and require in perl programming?
What is the closure in PERL?
Is perl compiler or interpreter?
Write syntax to use grep function?
What is the difference between perl array and perl hash?
What are different data types that perl supports. Elaborate on them.
What are the different types of perl operators?
what is Chop & Chomp function does?
Explain goto name?
What does Perl do if you try to exploit the execve(2) race involving setuid scripts?
Perl regular expressions are greedy" what does this mean?
How to copy a file in perl?