Bill and Randy,

No - I meant if my main is my_main.pl and my module is
my_mod.pm .... what special variable in my_mod.pm will
= "my_main.pl"

I found I can do this using 'caller'...

($package,$filename,$line) = caller; # in my_mod.pm

and $filename = "my_main.pl"

I was looking for a special variable like $0 that
would already have this value for $filename

I would think that __FILE__ would = "my_mod.pm" ...

Thanks,

John


--- "Randy W. Sims" <[EMAIL PROTECTED]>
wrote:

> $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>
> 


=====
John V. Pataki
Logged in to my Yahoo Mail account on the web.

_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to