Re: reflection in perl

From: Paul Johnson (
Date: 10/07/04

Date: Thu, 7 Oct 2004 12:33:18 +0200
To: Michael Seele <>

On Thu, Oct 07, 2004 at 11:28:44AM +0200, Michael Seele wrote:

> i'm new to perl and i want to know if perl has reflection like java?
> how can i acces reflection and how powerfull is the reflection in perl?

You might want to narrow this down a bit to get real information, but: says

] The reflection API represents, or reflects, the classes, interfaces,
] and objects in the current Java Virtual Machine. You'll want to use
] the reflection API if you are writing development tools such as
] debuggers, class browsers, and GUI builders. With the reflection API
] you can:

] * Determine the class of an object.


] * Get information about a class's modifiers, fields, methods,
] constructors, and superclasses.
] * Find out what constants and method declarations belong to an
] interface.

You would probably use can(), @ISA and, depending of the base type of
the class, exists().

] * Create an instance of a class whose name is not known until
] runtime.

bless $obj, $class

] * Get and set the value of an object's field, even if the field name
] is unknown to your program until runtime.

$obj->{$field} = $value

] * Invoke a method on an object, even if the method is not known
] until runtime.


] * Create a new array, whose size and component type are not known
] until runtime, and then modify the array's components.

my @arr;
$arr[$index] = $value

You can also access the symbol table at runtime, and use the B modules
to access a lot of internal information. But I don't think you'll need
to at first.

You'll need to learn to think the Perl way to get the best from the
language. You could program Perl as if it were Java, and do everything
you want to, but if you're using Perl, you might as well work to its

Paul Johnson -

Relevant Pages

  • Re: reflection in perl
    ... > i'm new to perl and i want to know if perl has reflection like java? ... > how can i acces reflection and how powerfull is the reflection in perl? ... my $class = shift(); ... sub print { ...
  • Re: Soft Reference to object properties
    ... and it cannot really be compared to what you can do in dynamically typed languages like JavaScript and Perl. ... Reflection in C# is indeed a neat and useful feature, but it comes at a price: you avoid compile time type check, and in many cases you will pay a noticable performance penalty. ... Well, if you need some kind of config scheme where an external config file tells what classes to instansiate or which namespaces to search in, reflection is probably the way to go. ... Maybe someone has fought with a similar problem before and cooked up a design pattern for it: ...
  • Re: Table to list tool
    ... project investigatoraward body ... reflection of what I've used before. ... If you knew Perl you would not ... Python may well be the new Perl, so you could skip a generation. ...
  • Re: Data::Dumper for Java?
    ... Sam wrote or quoted: ... > e.g. in Perl: ... representation of the contents of the object. ... it's a case of using reflection to access the data. ...
  • Re: Subject: Question: Dynamically Raise Event using Reflection API
    ... I tried to find a way to dynamically raise event using Reflection API. ... the GetRaiseMethod of the EventInfo object ...