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.


In reply to Re: printing references by asarih
in thread printing references by mhearse

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.