<?xml version="1.0" encoding="windows-1252"?>
<node id="417192" title="eval('__PACKAGE__') is always main?!!!" created="2004-12-23 14:19:10" updated="2005-06-13 01:49:34">
<type id="115">
perlquestion</type>
<author id="184322">
gmpassos</author>
<data>
<field name="doctext">
Is that right?
&lt;code&gt;
package foo ;
print eval('__PACKAGE__');
&lt;/code&gt;
&lt;b&gt;Output:&lt;/b&gt;
&lt;code&gt;
main
&lt;/code&gt;
The sense tell me that should be foo! I tested this on Perl 5.6.1 and 5.8.3 and the output is the same.
&lt;p&gt;
Is that a bug or an odd behavior?
&lt;p&gt;
&lt;b&gt;UP:&lt;/b&gt; Note that the main idea is not how to get foo as value. The idea is that __PACKAGE__ will always point to main unless we define the package inside the eval like this: eval('package foo ; __PACKAGE__'). This is very odd, since any code evaluated will make references to the local pakcage and not main.
&lt;!-- Node text goes above. Div tags should contain sig only --&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-184322"&gt;
&lt;p&gt;
Graciliano M. P.&lt;br&gt;
"Creativity is the expression of liberty".
&lt;/div&gt;&lt;/div&gt;</field>
</data>
</node>
