Search code examples
perlglob

How to you distinguish a symbol table from a regular hash variable?


Is there any way to tell whether a hash reference is referring to a symbol table?

That is, how could the function

sub foo {
    my ($hashref) = @_;
    ...
}

know whether it had been invoked as

foo( \%main:: )

rather than

foo( \%main )

?

The application is a function that sometimes tie's hash variables, but I'd want to avoid trying to tie a symbol table.


Solution

  • It looks like this can be done from the C API using HvNAME. The following is from perlapi:

    HvNAME

    Returns the package name of a stash, or NULL if stash isn't a stash. See SvSTASH , CvSTASH .

    1. char* HvNAME(HV* stash)