in reply to Code asks, in what file do I live?

use caller().
($packeage, $filename, $line) = caller;
Called without an arguement, caller() returns the above, about the currently executing subroutine.

Replies are listed 'Best First'.
Re^2: Code asks, in what file do I live?
by dave_the_m (Monsignor) on Sep 23, 2004 at 19:19 UTC
    Called without an arguement, caller() returns the above, about the currently executing subroutine.
    Er, actually it returns stuff about the caller of the current subroutine.

    Dave.

      Er, actually it returns stuff about the caller of the current subroutine

      Well, if you pass in 0 (caller(0)) then you get the caller information for the current stack frame plus some more information.

      my $filename = (caller(0))[1];
        Well, if you pass in 0 (caller(0)) then you get the caller information for the current stack frame
        And the current stack frame still shows who called you, not who you are. You can't determine the current filename using caller:
        $ cat /tmp/x sub f { my $f = (caller(0))[1]; print "I am: ", __FILE__, "\n"; print "caller: $f\n"; } 1; $ perl585 -e 'require "/tmp/x"; f()' I am: /tmp/x caller: -e $

        Dave.

        A reply falls below the community's threshold of quality. You may see it by logging in.