develooper Front page | perl.perl5.porters | Postings from April 2003

package __PACKAGE__ - bug or feature

Thread Next
From:
Tels
Date:
April 18, 2003 01:30
Subject:
package __PACKAGE__ - bug or feature
Message ID:
perl.perl5.porters-74396@nntp.perl.org
-----BEGIN PGP SIGNED MESSAGE-----

Moin,

Yesterday I wrote something like this:

        package Foo;
        ...
        package __PACKAGE__;

and somehow expected it to switch back to the former package (this was
inside a "required" file, where I didn't know exactly what the former
package was).

Of course, this was a tinko (Thanx Andreas for this word), because
__PACKAGE__ refers to the current package, not the last one! So it didn't
work. 

However, it still does not exactly what I expect:

        te@null:~>cat package.pl
        #!/usr/bin/perl -w
        BEGIN { print __PACKAGE__,"\n"; }
        package Foo;
        BEGIN { print __PACKAGE__,"\n"; }
        package main;
        BEGIN { print __PACKAGE__,"\n"; }
        package __PACKAGE__;
        BEGIN { print __PACKAGE__,"\n"; }
        te@null:~> perl package.pl
        main
        Foo
        main
        __PACKAGE__


Shouldn't the last line be main, even though that seems to be a silly
feature (since it is effectivel an NOOP)?

Best wishes,

Tels

- -- 
 http://www.notcpa.org/ You still can run any code on your CPU. How long?
 Signed on Fri Apr 18 10:32:56 2003 with http://bloodgate.com/tels.asc

 perl -MDev::Bollocks -le'print Dev::Bollocks->rand()'
 efficiently implement bricks-and-clicks segments

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: When cryptography is outlawed, bayl bhgynjf jvyy unir cevinpl.

iQEVAwUBPp+4PncLPEOTuEwVAQEBQAf/RCDiEzacwuFyraQjvuHjianEZcVY6wxH
2wfgVTMAFbml93bvnLQW/rYevllRAcjmRgxEtmwq7omcMNZ9UJO26JJVVYxltfps
Rj0ETG24yY86Jl3EozJrZexP2T4AUvbNN8G3mPYrOQKjGDJ5+eChh0u2GIfnO8fy
SK3n7Tfc/bR500/tJurC2005r2vJXNvjDHyLJsk63wi7C7WWXjqScpyzM1ymC1D2
pnNce1WCNIAxe6bnDU2Xl3Bpm9mB7tFE/erjzEpVcbko7Lcngqctg424nycfs6C6
V2fHS62/nScSkf8Pdwmof+o6aI7jsAOzII8ER3YV7+ELrP0GLE33uA==
=pWLs
-----END PGP SIGNATURE-----

Thread Next


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