Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

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.


cutegirl wrote:

Quoted text here. Click to load it

You need 2 underscores on both sides.

    print __PACKAGE__;


Quoted text here. Click to load it

If you learn your way around the documentation that comes with
perl, then you won't be dependant on others for simple questions.

Perl's docs are large so it is easy to miss the right place to look,
but you should at least take a shot at it.

Quoted text here. Click to load it

Books are nice, but they are not the 1st reference for Perl.

The std docs are the 1st reference for Perl, so when something
in a book isn't working right, it is wise to try verifying what
the book says in the Perl docs.

See the "Special Literals" section in:

   perldoc perldata

paying particular attention to the characters that make
up the literal that you are using.

Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher0cmdat/"

Site Timeline