I’m not a perl programmer so sorry if this is obvious. There is a perl package on a system I am working on that I want to modify, but I don’t know which other programs are using it. I can tell that at least three cron jobs use it because I put these lines into the file:
open(STDOUT, '>', "/var/log/SS_logs/packageAlert.log");
open(STDERR, '>', "/var/log/SS_logs/packageAlert.error.log");
print "\nThe program packageAlert.pm is running on " . `date` . "\n";
and 10 minutes later I got three lines in my log. There may be more that call it on a daily or weekly basis and it could be called in web pages as well.
I searched for occurrences of the package with grep -R "SS::alert" . so know that there are 20 or so scripts and web pages that may use the package.
Is there a function that I can call to find out which file called the package?
The caller function can tell you the file that called you (this is the same thing that lets modulinos work).
use v5.10;
say "Loading " . __FILE__ . " at " . localtime();
use File::Spec::Functions qw(rel2abs);
my $calling_file = rel2abs( (caller(0))[1] );
say "Loaded by $calling_file";
1;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With