For completeness sake (and because I might want to refer to this in the future), here's my code with named params. Thanks for your help and patience.

Dragon.pm
package Dragon; use strict; use Data::Dumper; sub new() { my $class = shift; # get class so constructor can be inhe +rited my $self = {}; bless ($self,$class); $self->_init( @_ ); # call _init here or in subclass $self->awaken; # arise! return $self; } sub _init { my $self = shift; my %args = @_; foreach my $key qw(NAME AGE COLOR) { $self->{$key} = $args{$key}; } } sub get_name { my $self = shift; return $self->{NAME} || "nameless"; } sub get_age { my $self = shift; return $self->{AGE} || "ageless"; } sub get_color { my $self = shift; return $self->{COLOR} || "obscure"; } sub awaken { my $self = shift; ($self->get_name eq "nameless") ? print "A " : 0; print $self->get_name .", "; ($self->get_name ne "nameless") ? print "the " : 0; print $self->get_age .", "; print $self->get_color ." dragon awakens from his slumber!\n"; } 1;
Trogdor.pm
package Trogdor; use strict; use base qw(Dragon); sub new { my $class = shift; $class->SUPER::new( NAME => "Trogdor", AGE => "one year old", COLOR => "green", @_, # allows us to override defaul +ts ); } sub burninate { my $self = shift; print $self->get_name ." burninates the land!\n"; } 1;
dragons.pl (test script)
#!/usr/bin/perl use strict; use Trogdor; my $d = new Trogdor(); # create Trodgor my $e = new Dragon(NAME => 'Smaug'); # create Smaug my $f = new Dragon(); # create anonymous dragon

----------
Using perl 5.8.1-RC3 unless otherwise noted. Apache/1.3.33 (Darwin) unless otherwise noted. Mac OS X 10.3.9 unless otherwise noted.

In reply to Re^4: oo design q: SUPER::_init by alienhuman
in thread oo design q: SUPER::_init by alienhuman

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.