Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > How to get the class name from the reference to an object?

Reply
Thread Tools

How to get the class name from the reference to an object?

 
 
Peng Yu
Guest
Posts: n/a
 
      06-06-2010
Suppose I new an object. Is there a way to get the class name from the
reference to the object?
 
Reply With Quote
 
 
 
 
sreservoir
Guest
Posts: n/a
 
      06-06-2010
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."
 
Reply With Quote
 
 
 
 
Jens Thoms Toerring
Guest
Posts: n/a
 
      06-06-2010
Peng Yu <(E-Mail Removed)> 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 ___ http://www.velocityreviews.com/forums/(E-Mail Removed)
\__________________________ http://toerring.de
 
Reply With Quote
 
Dr.Ruud
Guest
Posts: n/a
 
      06-06-2010
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:umper;

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
 
Reply With Quote
 
chad
Guest
Posts: n/a
 
      06-09-2010
On Jun 6, 3:35*pm, (E-Mail Removed) (Jens Thoms Toerring) wrote:
> Peng Yu <(E-Mail Removed)> 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
 
Reply With Quote
 
Jens Thoms Toerring
Guest
Posts: n/a
 
      06-09-2010
chad <(E-Mail Removed)> wrote:
> On Jun 6, 3:35*pm, (E-Mail Removed) (Jens Thoms Toerring) wrote:
> > Peng Yu <(E-Mail Removed)> 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"?


Well, in Perl I'm more used to the term "package" (and ref()
returns the "package name" for blessed objects according to
the documentation) than "class" - thus I was not 100% sure
what the OP wanted...
Regards, Jens
--
\ Jens Thoms Toerring ___ (E-Mail Removed)
\__________________________ http://toerring.de
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
How to get the class name inside the class's member function? Peng Yu C++ 2 07-10-2008 07:31 AM
How to get name of 'Caller' class from 'Called' class (ASP.NET) =?Utf-8?B?SG1udA==?= ASP .Net 5 06-25-2006 03:44 PM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM
Re: Urgent! how to get object name, method name and attribute name based on the strings? ding feng C++ 2 06-25-2003 01:18 PM



Advertisments