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?

Answers were Sorted based on User's Feedback



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

Answer / kuldip singh behal

if we are looking for occurrences of single character in a
string then we can use TR command
syntax: tr///
example:
$string="The lion group will meet me after lunch";
and we are looking for the occurrences of character 'l' in
the given string. then we can write tr like
$count = ($string=~tr/l//);
print "l is coming $count time(s)";

but for multiple characters look up we have to use:

$string = "-9 55 48 -2 23 -76 4 14 -44";
while ($string =~ /-\d+/g) { $count++ }
print "There are $count negative numbers in the string";


Donated by :- Kuldip singh behal

Is This Answer Correct ?    10 Yes 0 No

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

Answer / ramya

while ($string =~ /<pattern>/g) { $count++ }

Is This Answer Correct ?    9 Yes 3 No

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

Answer / shah faisal

($count)=$string =~ s/<pattern>/<pattern>/g;

Is This Answer Correct ?    4 Yes 3 No

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

Answer / 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

More CGI Perl Interview Questions

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

0 Answers  


Explain what is perl language?

0 Answers  


“Perl regular expressions match the longest string possible”. What is the name of this match?

0 Answers  


Explain cpan?

0 Answers  


Perl uses single or double quotes to surround a zero or more characters. Are the single(' ') or double quotes (" ") identical?

0 Answers  


How do I print the entire contents of an array with Perl?

0 Answers  


How many types of primary data structures in Perl and what do they mean?

0 Answers  


How do I sort a hash by the hash key?

0 Answers  


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

0 Answers  


Show the use of sockets for the server and client side of a conversation?

0 Answers  


How to close a file in perl?

0 Answers  


How to turn on Perl warnings? Why is that important?

0 Answers  


Categories