in reply to how to get a subroutine name?
For historic reasons, I would propose to define a sub called __FUNC__ that returns the name of the subroutine in which it was called, see the following example:
use strict; use warnings; sub __FUNC__ { (caller 1)[3] } sub func { print "We are now in ", __FUNC__, "\n"; } func();
UPDATE: Removed a duplicated "print".
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: how to get a subroutine name?
by LanX (Saint) on Jun 26, 2013 at 12:04 UTC | |
by hdb (Monsignor) on Jun 26, 2013 at 12:25 UTC | |
Re^2: how to get a subroutine name?
by clueless newbie (Curate) on Jun 26, 2013 at 12:49 UTC | |
by hdb (Monsignor) on Jun 26, 2013 at 12:54 UTC | |
by tobyink (Canon) on Jun 26, 2013 at 14:05 UTC |
In Section
Seekers of Perl Wisdom