in reply to What type are you? Mr Hash, Sir Array, or Miss Scalar?

The Scalar::Util module has a function 'reftype':

reftype EXPR

If EXPR evaluates to a reference the type of the variable referenced is returned. Otherwise "undef" is returned.

$type = reftype "string"; # undef $type = reftype \$var; # SCALAR $type = reftype []; # ARRAY $obj = bless {}, "Foo"; $type = reftype $obj; # HASH

Hugo

Replies are listed 'Best First'.
Re: Re: What type are you? Mr Hash, Sir Array, or Miss Scalar?
by Fletch (Bishop) on May 12, 2004 at 14:31 UTC

    The builtin ref does this just fine for unblessed references. And unless you're going to be impolite and break encapsulation you may not want to go mucking about with other class' internals.

Re: Re: What type are you? Mr Hash, Sir Array, or Miss Scalar?
by Doraemon (Beadle) on May 12, 2004 at 14:48 UTC
    Ahhh, thanx, or else i will looked so DUMB :)
    Yes, i mean programatically, not me identifying variables (i know that, already).
    This is important when we using reference, since i need to know what the reference is pointing to...

      have a look at   perldoc -f ref,   as Fletch already pointed out.

      Cheers, Sören

Re: Re: What type are you? Mr Hash, Sir Array, or Miss Scalar?
by Doraemon (Beadle) on May 12, 2004 at 15:42 UTC
    I've tried it out, but why is this doesn't work?
    I've used ref instead, but never on advanced level (on class etc.