in reply to Where is implementation of $0 in Perl source code

Consider the following:
$ cat /tmp/Foo.pm sub f { print $0, ",", (caller)[1], "\n"; } f(); 1; $ perl -I/tmp -MFoo -e1 -e,/tmp/Foo.pm $
Reading from the $0 variable is implemented in the "case '0'" branch of the switch within the function Perl_magic_get() in mg.c.

Caller is implemented by the pp_caller() function in pp_ctl.c

Dave.

Replies are listed 'Best First'.
Re^2: Where is implementation of $0 in Perl source code
by dave_the_m (Monsignor) on May 27, 2015 at 18:30 UTC
    Update: I just noticed that you specified within a single file. Ok:
    $ perl -le'$0="Foo"; sub f { print "$0,", (caller)[1] } f()' Foo,-e

    Dave.