caller (), , , .
use warnings;
use strict;
package X;
sub new
{
bless {};
}
sub getdownonthatcrazything
{
my ($self) = @_;
my (undef, $file, $line) = caller ();
open my $in, "<", $file or die $!;
while (<$in>) {
if ($. == $line) {
goto found;
}
}
die "Something bad happened";
found:
if (/\$(\w+)\s*->\s*getdownonthatcrazything\s*\(\)/) {
my $variable = $1;
print "I was called by a variable called \$$variable.\n";
}
close $in or die $!;
}
1;
package main;
my $x = X::new ();
$x->getdownonthatcrazything ();
my $yareyousofunky = X::new ();
$yareyousofunky->getdownonthatcrazything ();
:
$ ./getmycaller.pl
I was called by a variable called $x.
I was called by a variable called $yareyousofunky.
, . , FindBin @INC ..
user181548