in reply to Re: tr faster than eq?
in thread tr faster than eq?

Is it possible that perl was having to eval the strings each time the sub was called, thus skewing the results?

No, it's because they are evaluated somewhere without access to the lexical $string, so they act upon the undefined global $string. Your solution causes the test cases to be compiled where $string is still in scope.

Replies are listed 'Best First'.
Re^3: tr faster than eq?
by thor (Priest) on Mar 10, 2005 at 19:22 UTC
    While what you say makes sense, why am I not getting a Use of uninitialized value in string when that code is run? warnings are turned on...that is unless it's because the eval happens in the Benchmark package and not the main package.

    thor

    Feel the white light, the light within
    Be your own disciple, fan the sparks of will
    For all of us waiting, your kingdom will come

      use warnings is block-scoped. The file is a block. Since it's being evaled in another file, your use warnings doesn't take effect.

      perl -w and $^W = 1; are scopped differently. Use these, or add use warnings inside the q(), and you'll see a gazillion warnings (one for every run).