in reply to Re^4: Subroutines with differing behaviour created from AUTOLOAD
in thread Subroutines with differing behaviour created from AUTOLOAD

... but doesn't it also negate the symbol table-insertion techniques? The eval'd code will have to be parsed anew each time the sub is called.
Not so. The evals return code references which are stuffed into the package symbol table to make accessor methods; a subsequent call to the same method will find it and not call AUTOLOAD.

The purpose of the eval is to bind $field at the time AUTOLOAD happens. It does this as it is in the string passed to eval without an escape (all other variables are escaped). With the original, $field is not bound to a specific value, but forms a closure, and is bound to the calling pad (hence it will share values between instances). The eval solution gives you a fresh op tree each time AUTOLOAD is called.

--
I'm Not Just Another Perl Hacker

  • Comment on Re^5: Subroutines with differing behaviour created from AUTOLOAD