in reply to getting a subroutine's name
caller() has more params and they can be useful, eg. line number etc. But basically if one of my library routines gets bogus input, then I usually just need to know the name of the caller and the name of previous caller to figure out where bogus input came from.#!usr/bin/perl -w use strict; sub whoami { (caller(1))[3] }; sub whowasi { (caller(2))[3] }; some_sub(); sub some_sub { print "Now inside some_sub\n"; print " called_by ". whoami.".\n"; another_sub(); } sub another_sub { print "Now inside another_sub\n"; print " called by ". whoami(). " \n"; print " previous sub ". whowasi(). " \n"; } __END__ Prints: Now inside some_sub called_by main::some_sub. Now inside another_sub called by main::another_sub previous sub main::some_sub
|
|---|