On 05/21/2018 11:04 PM, ToddAndMargo wrote:
Hi All,

I need to know the name of the subroutine I am in.

This is the way I use to do it in Perl 5:

          (my $Name = (caller(0))[3] ) ~~ s{.*::}{};

How do I do it in Perl 6?

Many thanks,
-T


Follow up:  based on Yary's wonderful advice, this is my keeper
on the subject:

<perl6.subs.name.of.sub.txt>

perl6: what is the name of the subroutine you are currently in:

It is:
     &?ROUTINE.name
     callframe(0).code.name

$ p6 'sub flowers() { say "My subroutine name is <", &?ROUTINE.name, ">" }; flowers;'
My subroutine name is <flowers>


$ p6 'sub flowers() { say "My subroutine name is <", callframe(0).code.name, ">" }; flowers;'
My subroutine name is <flowers>

Reply via email to