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
Explain goto label?
What does `new $cur->{LINK}' do? (Assume the current package has no new() function of its own.)
How to prevent file truncation in perl?
Give an example of the -i and 0s option usage.
What are the two ways to get private values inside a subroutine?
Explain goto expr?
In CPAN module, name an instance you use.
How do I sort a hash by the hash value?
How to code in perl to implement the tail function in unix?
Differentiate between arrays and list in perl.
Difference between the variables in which chomp function work ?
Explain returning values from subroutines?
What do you mean by context of a subroutine?
How can we create perl programs in unix, windows nt, macintosh and os/2 ?
What is warn function in perl?