in reply to Retrieving classname from an object

You can get it from ref() or get it more directly/accurately from Scalar::Util::blessed(). (ref, e.g., will return 'ARRAY' for an unblessed array reference or 'HASH' for an unblessed hash reference, while blessed will only return results for blessed references).

Updated.

  • Comment on Re: Retrieving classname from an object

Replies are listed 'Best First'.
Re^2: Retrieving classname from an object
by Hue-Bond (Priest) on Jul 10, 2006 at 23:57 UTC
    ref, e.g., will return 'ARRAY' for an unblessed array reference

    Which is amusing:

    { package ARRAY; sub new { return bless \shift; } } print join ' ', ref \@{[]}, ref ARRAY->new ("something"), "\n"; __END__ ARRAY ARRAY

    --
    David Serrano

Re^2: Retrieving classname from an object
by monkeyhelper (Initiate) on Jul 10, 2006 at 23:28 UTC
    I had a look at ref and it didn't seem to provide this info - Do you have an example (out of curiosity) ? I'll use Scalar::Util for now. Thanks for the help.
      my $class = ref $object;
        Ah yes - to quote from Programming Perl : "If the referenced object has been blessed into a package, then that package name is returned instead."
        hehe