How fast is an EVAL String

Aaron Wigley wigs at
Tue Apr 27 02:43:52 CDT 2004

On Tue, Apr 27, 2004 at 03:32:03PM +1000, Scott Penrose wrote:
> The whole purpose of the ->data1|2 method is to replace this 
> string with a set of methods called one after another. This can be done 
> with recursion, iteration or a string eval. I think that if we had tail 
> recursion that recursion would probably be the fastest, but since we 
> don't then iteration seems now to be the fastest.

Alternatively, if it is a repeated-enough occurance, you could compile
the string into a coderef representing the cascaded method calls required.

    $str = '';
    $str =~ s/\./->/g;
    $accessor = eval q/
        sub {
            return \$_[0]->$str;
    $mutator = eval q/
        sub {
            my (\$self, \@args) = \@_;

    $v = &$accessor();


More information about the Melbourne-pm mailing list