in reply to Auto-detecting module usage

Nobody's mentioned $0 yet, so I will, because that actually does what you're asking for in your question (i.e. give you the name of the script which is running when your module is loaded). However, judging from the purpose you describe, you'll be better off with diotalevi's suggestion, to use caller() to determine what has loaded your module, because that will return the file your module was loaded from. For example if you have, in Flim.pm

package Flim; sub new { print "Caller: ".join("-",caller())."\n"; print '$0: '.$0."\n"; }
in Flam.pm:
package Flam; use Flim; sub new { Flim->new(); }
and in flimflam.pl:
use Flam; Flam->new();
This will print out
Caller: Flam-/Flam.pm-3 $0: flimflam.pl

There are ten types of people: those that understand binary and those that don't.

Replies are listed 'Best First'.
Re^2: Auto-detecting module usage
by Anonymous Monk on Jan 24, 2006 at 16:15 UTC
    Thanks, I had completely forgotten about $0. That's exactly what I wanted. :-)