in reply to returning filename of module used

Assuming your module is normally named (e.g. named Foo::Bar and stored in a file Foo/Bar.pm), then this should work:
package Foo::Bar; sub whence { my $fp = __PACKAGE__; $fp =~ s,::,/,g; $fp .= '.pm'; $main::INC{$fp} }
But I'm sure there are boundary cases where this doesn't quite cut it...

Replies are listed 'Best First'.
Re^2: returning filename of module used
by Tanktalus (Canon) on May 17, 2005 at 14:31 UTC

    Note that %INC (and likely @INC) is actually a global global. That is, it is available in every package:

    package Foo; sub whence { my $fp = shift; $fp =~ s=::=/=g; $fp .= '.pm'; $INC{$fp} } package main; use warnings; print Foo::whence('warnings'),$/;
    Works just fine. ;-) I make minor changes to your example because I didn't use a "normally named" package to put whence into.