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

How will you declare a variable in perl?

1027


We all know private variables exist in perl. But do private METHODS exist in perl ? Eg ?

2562


Which operator in perl is used for the concatenation of two strings?

1042


How do you set environment variables in perl?

1103


Can you add two arrays together?

986


Why is it hard to call this function: sub y { "because" } ?

1008


What are some common methods to all handles in perl?

976


List the data types that Perl can handle?

1116


How would you ensure the re-use and maximum readability of your perl code?

984


Which functions in Perl allows you to include a module file or a module and what is the difference between them?

1092


Explain which feature of PERL provides code reusability?

1269


How can you call a subroutine and identify a subroutine?

1033


Explain subroutine?

974


What does length(%HASH) produce if you have thirty-seven random keys in a newly created hash?

1068


Explain about the applications of perl?

1017