Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find out which scripts are calling a perl package

Tags:

perl

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?

like image 456
JScarry Avatar asked Mar 12 '21 22:03

JScarry


Video Answer


1 Answers

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;
like image 58
brian d foy Avatar answered Oct 23 '22 23:10

brian d foy