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.