develooper Front page | perl.perl5.porters | Postings from January 2001

[ID 20010123.028] __PACKAGE__ token in eval() has wrong value

From:
mjd
Date:
January 23, 2001 02:04
Subject:
[ID 20010123.028] __PACKAGE__ token in eval() has wrong value
Message ID:
20010123100432.22571.qmail@plover.com
Path: newshog.newsread.com!bad-news.newsread.com!netaxs.com!newsread.com!newsfeed.mathworks.com!oleane.net!oleane!isdnet!diablo.theplanet.net!news.theplanet.net!newspost.theplanet.net!not-for-mail
From: "Hugh Williams" <hugh@grugach.freeserve.co.uk>
Newsgroups: comp.lang.perl.misc
Subject: Behaviour of __PACKAGE__ inside eval
Date: Mon, 22 Jan 2001 21:44:42 -0000
Organization: Customer of Energis Squared
Lines: 36
Message-ID: <94i96o$q7f$1@news8.svr.pol.co.uk>
NNTP-Posting-Host: modem-108.anfauglith.dialup.pol.co.uk
X-Trace: news8.svr.pol.co.uk 980199448 26863 62.136.110.108 (22 Jan 2001 21:37:28 GMT)
NNTP-Posting-Date: 22 Jan 2001 21:37:28 GMT
X-Complaints-To: abuse@theplanet.net
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4133.2400
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400
Xref: bad-news.newsread.com comp.lang.perl.misc:373677

Hi,

I found this strange bit of behaviour related to __PACKAGE__ and eval. The
following bit of code:

$a=1;
package no2;
$a=2;
print __PACKAGE__."\n";
print "$a\n";
print "$main::a\n";
eval <<'--END--'; # note single quotes - no interpolation
print __PACKAGE__."\n";
print "$a\n";
print "$main::a\n";
--END--

produces this output

no2
2
1
main
2
1

so although the variable $a in the eval statement resolves in the expected
namespace, the __PACKAGE__ symbol itself is inaccurate. Can anyone explain
what is happening here?

Thanks

Hugh







nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About