Do you know where your variables are? | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Hello Monks,
I was looking for a way to change the current subroutine name to an arbitrary value (which is unknown at compile time), in order to have caller() return this value. In particular, it is my ambition to inject a subroutine into an arbitrary package, and that subroutine should use NEXT, as the following code suggests: Unfortunately, this piece of code does not work as expected, because NEXT will use (caller(1))[3] to determine the calling function, and that won't yield $package . '::function'. You may verify this using the following script: The output is main::__ANON__, however I'd like it to be testpackage::function. One possible solution would be eval, but I don't like this much:
I know that I can trick caller() with goto &sub, however, I don't think that this gets me any further. Does anyone know a solution to my problem? In reply to How to fool caller() / use NEXT within a dynamic sub by betterworld
|
|