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?

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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Where the command line arguments are stored and if you want to read command-line arguments with Perl, how would you do that?

1092


What is a chop() function in perl?

1016


What does perl do in linux?

945


Can inheritance be used in perl? Explain with the help of an example.

991


What does cgi program store?

918


What can be done for efficient parameter passing in perl? Explain.

1033


There are two types of eval statements i.e. Eval expr and eval block. Explain them.

1034


Comment on data types and variables in perl.

927


What does redo statement do in perl?

1036


What are the arguements we normally use for perl interpreter?

963


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

1072


Explain the different types of data perl can handle.

898


Explain join function in perl?

960


How to remove a directory in perl?

992


Which of these is a difference between Perl and C++ ?

1050