valhalla418 has asked for the wisdom of the Perl Monks concerning the following question:

I can't find anything by searching so I've resorted to posting what's probably a very simple question.

If I pass a scalar into object method, how can I determine what type of value the scalar contains (either a basic scalar or a ref to an object hash)

The only way I know how to do this is shown in this ugly code snippet:

if ($myscalar =~ /HASH/) {print "Is a ref to an object hash\n";} else {print "Is a basic scalar\n";}

The idea of this is to pick up the HASH part of obj=HASH(0x12345678)

Replies are listed 'Best First'.
Re: Determining contents type of a Scalar
by Aristotle (Chancellor) on Feb 22, 2006 at 17:47 UTC
Re: Determining contents type of a Scalar
by sh1tn (Priest) on Feb 22, 2006 at 17:37 UTC
    See ref subroutine.
    perldoc -f ref


Re: Determining contents type of a Scalar
by xorl (Deacon) on Feb 22, 2006 at 17:45 UTC
    perl.com lists some possible ways (about midway down). To quote from the article "There are many, many ways to do this. Some even work."