Main Page | Report this Page
Computers Forum Index  »  Computer Languages (Perl - Modules)  »  _PACKAGE...
Page 1 of 1    

_PACKAGE...

Author Message
cutegirl...
Posted: Sun Aug 23, 2009 7:31 pm
Guest
I am new to Perl, so please excuse me for asking such a simple
question: The book I am reading gave an example of how to use the
"_PACKAGE_" token. The original code is like this:
package My::Module;
print _PACKAGE, "\n";
package My::Module::Heavy;
print _PACKAGE,"\n";

When I tried to run this code using Perl version 5.10.0, I encoutered
an error message, saying "No comma allowed after file handle". But
after I changed the code to: print "_PACKAGE_\n", all I got is
_PACKAGE printed out on the screen. It appears that the _PACKAGE_ is
just like a string if "use strict" is not enforced. Can anyone explain
why is this? Thank you very much.
 
Bart Lateur...
Posted: Mon Aug 24, 2009 1:51 am
Guest
cutegirl wrote:

Quote:
I am new to Perl, so please excuse me for asking such a simple
question: The book I am reading gave an example of how to use the
"_PACKAGE_" token. The original code is like this:
package My::Module;
print _PACKAGE, "\n";
package My::Module::Heavy;
print _PACKAGE,"\n";

When I tried to run this code using Perl version 5.10.0, I encoutered
an error message, saying "No comma allowed after file handle". But
after I changed the code to: print "_PACKAGE_\n", all I got is
_PACKAGE printed out on the screen. It appears that the _PACKAGE_ is
just like a string if "use strict" is not enforced. Can anyone explain
why is this? Thank you very much.

You need 2 underscores on both sides.

print __PACKAGE__;

--
Bart.
 
 
Page 1 of 1    
All times are GMT
The time now is Mon Nov 23, 2009 1:02 pm