note
BrowserUk
<blockquote><i>Are you sure this is the most efficient way to do this?</i></blockquote>
<p>Yes, I am quite sure.
<ol><li>[tr] doesn't make copies, it operates in-place.
</li><li>It is optimised internally to recognise that when the source and replacements are identical, it is in 'counting mode' only.
</li></ol>
<p>For multi-character substring counting avoid creating the huge list:<code>
$s = 'ab'x 10e6;;
++$n while $s=~ m[ab]g;;
print $n;;
10000000
</code>
<div class="pmsig"><div class="pmsig-171588">
<hr />
<font size=1 >
<div>With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'</div>
<div>Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.</div>
<div>"Science is about questioning the status quo. Questioning authority". </div>
<div>In the absence of evidence, opinion is indistinguishable from prejudice.
</div>
</font>
</div></div>
1025770
1026021