$Bill Luebkert wrote:
John V. Pataki wrote:


Is there a perl special variable that the module can
use which will == $0 in the main?


$0 works the same in a package as it does in main.  I assume
you are asking for an equivalent variable for the package.

You can print the filename, line number and package name :

print "file=", __FILE__, ", line=", __LINE__, ", pkg=", __PACKAGE__, "\n";

I know of no easy way to get the full path of the package other than
printing it out of %INC :

        print $INC{__PACKAGE__ . '.pm'}, "\n";


I thought he was asking a different question (though it's hard to tell). In Ruby[1], if you want to put some executable code in a module that is only executed if the module file is run directly (as opposed to being 'required'), you would use the incantation:


if $0 == __FILE__
    # ...
end

If you run the file directly: `ruby module.rb` then it will be executed, but if it is included from a ruby script, it is not.

I think there is a similar way to put code in a perl package that behaves similarly, but I can't think of the incantation at the moment... I've been spending too much time playing with Ruby.

1. <http://ruby-lang.org>
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to