Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

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)

Replies are listed 'Best First'.
Re^2: How to get the name from a reference
by chromatic (Archbishop) on Mar 30, 2009 at 17:26 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://754190]
[Eily]: BTW LanX, you should try typing a few random chars at the beginning of each message. This will prevent expansion :P
[LanX]: qwiud you sthink so?
[LanX]: zxwqbd good idea! :)
LanX embraces his new habit spqopiwjdnq
[ambrus]: qQUkZTmHTuKxStGT- BzTIK9gdudif7TkTLI t3mnF144UaAZjkknXY 8nN-QM19wHBsTrp5vB lEYU_Kksa7X1RIBB4x EWLD5X7SW3jGX5ryfN OMn_yL5FTdQxzjhtyX mKN9sjUCzBNHK5Rrp0 S2WMUvIb1i9aZFgjtq VR0GH1bjPMvm1G16iz hBqc1U6toPd4FbJOFj VsOeT745AN1_pO88rD SRAYKtBZwCZedESZmN mvutrOTHiSNwflB- pRfn_k
[Eily]: so far it seems to work
Your Mother reminds the monks they should be grateful not to share an office, lest they be subjugated to constant inanities like, "Czech please!"
[LanX]: what's strange is that the "Cowboy you said this already" message is missing #dqiwd
[LanX]: YM: BTW learn to mute your humanity
[Your Mother]: Cumin? Now I want tacos...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (17)
As of 2017-03-27 16:53 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (320 votes). Check out past polls.