Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: How to get the name from a reference

by repellent (Priest)
on Mar 30, 2009 at 17:12 UTC ( #754190=note: print w/ replies, xml ) Need Help??


in reply to How to get the name from a reference

As far as I know, we can only do it for CODE references:

# obtain CODEref name use B; sub coderef2name { my ($coderef) = @_; return unless UNIVERSAL::isa($coderef, "CODE"); my $obj = B::svref_2object($coderef); return $obj->GV->STASH->NAME . "::" . $obj->GV->NAME; }

Update: Changed to use GV->STASH->NAME instead.

Note that:
> perl -MDevel::Peek -e '$var = 123; Dump \$var; sub my_sub {}; Dump \ +&my_sub' SV = RV(0x8073260) at 0x804cc28 REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x8065648 SV = IV(0x8068920) at 0x8065648 REFCNT = 2 FLAGS = (IOK,pIOK) IV = 123 SV = RV(0x8073260) at 0x804cc28 REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x8064b34 SV = PVCV(0x8061538) at 0x8064b34 REFCNT = 2 FLAGS = () IV = 0 NV = 0 COMP_STASH = 0x804cb50 "main" START = 0x806d6a8 ===> 1053 ROOT = 0x806fa68 XSUB = 0x0 XSUBANY = 0 GVGV::GV = 0x8065684 "main" :: "my_sub" FILE = "-e" DEPTH = 0 FLAGS = 0x0 OUTSIDE_SEQ = 91 PADLIST = 0x8064b04 PADNAME = 0x804cce8(0x8088758) PAD = 0x8065678(0x805e5b0) OUTSIDE = 0x804cd78 (MAIN)


Comment on Re: How to get the name from a reference
Select or Download Code
Re^2: How to get the name from a reference
by chromatic (Archbishop) on Mar 30, 2009 at 17:26 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://754190]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (8)
As of 2014-07-30 10:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (230 votes), past polls