introduction to Perl 5 for web developers Perl Objects To instantiate an object from a class, you need only call the class' "new" method such as:

     my $new_object = new ClassName;

For example,

     my $new_cat = new Cat("Fred", "white");

When you do so, the new() subroutine in that Cat class will be called. As you recall, the new() subroutine created a reference to an anonymous hash, blessed the reference, and returned it. Thus, $new_cat will store the reference to your cat object.

So once you have instantiated an actual cat object, you will need to know how to do things with it. How can I make Fred say "meow"?

Previous | Next | Table of Contents