From: Peng Yu on
Suppose I new an object. Is there a way to get the class name from the
reference to the object?
From: sreservoir on
On 6/6/2010 6:12 PM, Peng Yu wrote:
> Suppose I new an object. Is there a way to get the class name from the
> reference to the object?

perldoc -fref

--

"Six by nine. Forty two."
"That's it. That's all there is."
"I always thought something was fundamentally wrong with the universe."
From: Jens Thoms Toerring on
Peng Yu <pengyu.ut(a)gmail.com> wrote:
> Suppose I new an object. Is there a way to get the class name from the
> reference to the object?

The ref() function should return the name of the package of the
object - I guess that's what you mean by "class name".

Regards, Jens
--
\ Jens Thoms Toerring ___ jt(a)toerring.de
\__________________________ http://toerring.de
From: Dr.Ruud on
Peng Yu wrote:

> Suppose I new an object. Is there a way to get the class name from the
> reference to the object?


#!/usr/bin/perl -l

use Data::Dumper;

use Scalar::Util qw(
blessed
reftype
);

my $object = bless [], __PACKAGE__;

sub info { Dumper \@_ }

my $i;

print ++$i, ":\t", $_ for
$object->info(),
Dumper ( $object ),
ref ( $object ),
blessed( $object ),
reftype( $object ),
;

__END__


--
Ruud
From: chad on
On Jun 6, 3:35 pm, j...(a)toerring.de (Jens Thoms Toerring) wrote:
> Peng Yu <pengyu...(a)gmail.com> wrote:
> > Suppose I new an object. Is there a way to get the class name from the
> > reference to the object?
>
> The ref() function should return the name of the package of the
> object - I guess that's what you mean by "class name".
>

Is there more than one defintion to "class name"?

Chad