Maybe a 64/32-bit difference? But that works out marginally slower on my machine:

#! perl -slw use strict; use Benchmark qw[ cmpthese ]; cmpthese -1, { one_eval => q[ my $t = 1; eval qq[ sub count { \$_[0] =~ tr[$t][$t] } ]; my $c = 0; $c += count( $_ ) for 1 .. 1e6; print $c; ], many_evals => q[ my $t = 1; my $c = 0; $c += eval qq[ \$_ =~ tr[$t][$t] ] for 1 .. 1e6; print $c; ], loop => q[ my $t = 1; my $c = 0; for my $n ( 1 .. 1e6 ) { ++$c while $n =~ m[$t]g; } print $c; ], loop2 => q[ my $t = 1; my $c = 0; for my $n ( 1 .. 1e6 ) { $c += () = $n =~ m[$t]g; } print $c; ], }; __END__ C:\test>junk30 600001 600001 600001 (warning: too few iterations for a reliable count) 600001 600001 600001 (warning: too few iterations for a reliable count) 600001 600001 (warning: too few iterations for a reliable count) 600001 Subroutine count redefined at (eval 2000028) line 1. 600001 Subroutine count redefined at (eval 2000029) line 1. 600001 Subroutine count redefined at (eval 2000032) line 1. 600001 (warning: too few iterations for a reliable count) Rate many_evals loop2 loop one_eval many_evals 3.68e-002/s -- -97% -97% -98% loop2 1.06/s 2777% -- -7% -57% loop 1.14/s 3006% 8% -- -53% one_eval 2.44/s 6515% 130% 113% --

Another reason for not using it, is that it gets exponentially slower as the number of hits increases, due to the need to allocate large lists which then get discarded:

perl -MTime::HiRes=time -E"$m=1e5;$x='x'x$m; $t=time; $n=()=$x=~m[x]g; say +(time()-$t)/$m" 1.44867897033691e-006 perl -MTime::HiRes=time -E"$m=1e6;$x='x'x$m; $t=time; $n=()=$x=~m[x]g; say +(time()-$t)/$m" 1.46089999675751e-005

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re^3: Returning transliteration from eval by BrowserUk
in thread Returning transliteration from eval by albert

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.