On Wed, Jun 12, 2002 at 08:30:12PM -0700, W. Huang wrote:
> I have a refence to a hash, which is $hashref. I want to print out the
> name of the hash ( which is "%hash" ) from $hashref, but don't know how.
> Could you please help? thanks!
> 
> #-----
> %hash= {
>    apple => "red",
>    bana  => "yellow",
> };
> $hashref =\%hash;
> print ?hashref;
> #-----

I know of no way to get the name of the original variable out of a
reference, short of possibly XS trickery.  I doubt that information is even
tracked at that level.

You can, however, get the name of a variable from a glob or glob reference. 
For example:

    %hash = { ... };

    my $glob = *hash;
    print *{$glob}{NAME};


However, due to the obscurity of accessing globs in this manner, or dealing
with globs in general, I would not suggest you do this in production code. 
Dealing with globs is fairly advanced, and will probably not be well
understood by most others who come along to read and maintain your code.

What is the purpose of this?  Perhaps this list can suggest alternatives.


Michael
--
Administrator                      www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to