Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: eval('__PACKAGE__') is always main?!!!

by MarkusLaker (Beadle)
on Dec 23, 2004 at 20:13 UTC ( #417201=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://417201]
help
Chatterbox?
[shmem]: LanX: ah, that one. You'll get the bug reports also :P
[Discipulus]: upvote me! i'll make pm great again! ;=)
[shmem]: Discipulus reminds me of an irish saying: "I would guess a tomorrow can wait 'til this day is done" :-)
[LanX]: nite! :)
[Discipulus]: or a spanish one: ' qui mucho se despide no quiere despedirse'

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2017-04-29 22:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I'm a fool:











    Results (534 votes). Check out past polls.