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
Enlist the advantages of using c over perl?
Write a script to reverse a string without using perl's built in functions?
What are the advantages of programming in perl?
I have one question regarding to eval function. I know eval function is use for error checking but I am not able to understand below line. eval \'exec perl -S $0 ${1+\"$@\"}\' if 0; $0 for script name $@ set if error occur
Explain tk?
Explain what is perl language?
What are hashes?
Where the command line arguments are stored and if you want to read command-line arguments with Perl, how would you do that?
What are the steps involved when the cgi program starts running?
How to code in perl to implement the tail function in unix?
What is the importance of perl warnings? How do you turn them on?
Explain chop?
Explain use of ‘my’ keyword in perl?
Differences between die and exit.
Define perl scripting?