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

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.

Replies are listed 'Best First'.
Re^3: Code asks, in what file do I live?
by Steve_p (Priest) on Sep 23, 2004 at 20:27 UTC
    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.