in reply to printing references

There isn't a direct, simpe way of retrieving the name of a variable from a reference to it. There is probably a package in the Devel::* group (Padwalker?) that could be used to do this.

There are a couple of ways that you could do this yourself.

Of the three, I think I prefer the second option, but in truth, I think that any is taking a hammer to crack a nut!

Why do you want to do this? If the idea is to log the name of the array in error messages, you should probably be referring to the array by some logical name pertinent to what the sub is doing with the contents of the array rather than the name of a specific instance.

If the idea is to give you an indication of where the sub was called from with bad data, then you should probably look at the caller function which will allow you to access various information about code that called your sub including the file, package, line, subroutine and others. It also has the ability to track back through several levels of caller, and can be used to provide a complete callback trace of the path through the code that was followed.

If your purpose is to provide good information for debugging purposes when your sub gets bad input, then you would probably find the Carp module really useful as it will do all the work of obtaining and formatting the callback trace information for you.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
If I understand your problem, I can solve it! Of course, the same can be said for you.