Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: printing references

by asarih (Hermit)
on Sep 12, 2003 at 02:24 UTC ( #290900=note: print w/replies, xml ) Need Help??

in reply to printing references

I'm more or less thinking out loud, so I could be off-base here....

Having said that, here's what I think: when you pass a reference to a subroutine, it doesn't get the name of the referent, but the reference itself. Internally, reference is an RV. RV does not have a field for the name of the referent but only the address.

#!/usr/local/bin/perl -w use Devel::Peek; sub func { $ref = shift; Dump($ref); } @array=('a',5); func(\@array);
Here's the output:
SV = RV(0x12ebe8) at 0x11df50 REFCNT = 1 FLAGS = (ROK) RV = 0x122240 SV = PVAV(0x12b4d8) at 0x122240 REFCNT = 3 FLAGS = () IV = 0 NV = 0 ARRAY = 0x120950 FILL = 1 MAX = 3 ARYLEN = 0x0 FLAGS = (REAL) Elt No. 0 SV = PV(0x1134a8) at 0x1131ac REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x112d10 "a"\0 CUR = 1 LEN = 2 Elt No. 1 SV = IV(0x121204) at 0x1132a8 REFCNT = 1 FLAGS = (IOK,pIOK) IV = 5
The important part is the first four lines. It says that what is shifted doesn't remember anything about the referent's name. So unless you pass the referent's name along with the reference itself to the subroutine, you can't do what you want to.

Of course, I'd be happy to be wrong in this case.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2022-08-14 09:12 GMT
Find Nodes?
    Voting Booth?

    No recent polls found