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
in Flam.pm:package Flim; sub new { print "Caller: ".join("-",caller())."\n"; print '$0: '.$0."\n"; }
and in flimflam.pl:package Flam; use Flim; sub new { Flim->new(); }
This will print outuse Flam; Flam->new();
Caller: Flam-/Flam.pm-3 $0: flimflam.pl
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Auto-detecting module usage
by Anonymous Monk on Jan 24, 2006 at 16:15 UTC |