http://www.perlmonks.org?node_id=417201


in reply to eval('__PACKAGE__') is always main?!!!

To this humble initiate, it looks like a bug. In the following test program, the text inside the eval seems (correctly) to run in package P; the only difference that prepending 'package P' makes is to set __PACKAGE__ correctly.

[~/perl/test]$ cat package #!/usr/bin/perl use warnings; use strict; no strict 'vars'; sub speak($) { print __PACKAGE__, "::speak was passed '", $_[0], "'\n"; } $var = "\$main::var\n"; $var = $var; package P; sub speak($) { print __PACKAGE__, "::speak was passed '", $_[0], "'\n"; } $var = "\$P::var\n"; $var = $var; eval ' speak __PACKAGE__; print $var;'; eval 'package P; speak __PACKAGE__; print $var;'; [~/perl/test]$ ./package P::speak was passed 'main' $P::var P::speak was passed 'P' $P::var [~/perl/test]$

Markus