| |
 |
|
| Computers Forum Index » Computer Languages (Perl - Modules) » _PACKAGE... |
|
Page 1 of 1 |
|
| 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. |
|
|
| Back to top |
|
|
|
| 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. |
|
|
| Back to top |
|
|
|
|
|
All times are GMT
The time now is Mon Nov 23, 2009 1:02 pm
|
|