Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re^2: counting inside the loop

by sarvan (Sexton)
on Jul 01, 2011 at 11:09 UTC ( #912334=note: print w/replies, xml ) Need Help??

in reply to Re: counting inside the loop
in thread counting inside the loop

Hi, For this,
$count=($str=~ tr/($t1)//);

if $t1 has ab. i just want to count how many times ab is their in $str. together. not as seperately 'a' 'b'.

What can be done for that..

Replies are listed 'Best First'.
Re^3: counting inside the loop
by Anonymous Monk on Jul 01, 2011 at 11:27 UTC
      $s='finding related pages finding on the world wide web'; my $count=$s=~ m/finding/g; print $count;

      I expect the result as 2.. becus "finding" exists two times in $s. but the output is 1. Why??


        It is because you don't know how to copy/paste

        The extra  ( ) = are required --- probably the worst syntax in all of perl, but its what you need if you have built-in regexes without objects, and you don't store matches in an array.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://912334]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2023-09-26 19:32 GMT
Find Nodes?
    Voting Booth?

    No recent polls found