This and your previous question are both really about OO design. Think about what should be part of the interface for the base class and provide support for that. For example, if you want to have an object describe itself you could do something like:

use strict; use warnings; package Vehicle; sub new { my $class = shift; # Provide some defaults my $self = {wheels => 4, engine => 1800, doors => 4}; return bless $self, $class; } sub describe { my $self = shift; return <<"desc"; My engine is $self->{engine}cc. I have $self->{wheels} wheels and $self->{doors} doors. desc } package Car; our @ISA = ('Vehicle'); sub new { my $class = shift; my $self = new Vehicle ($class); $self->{colour} = 'blue'; return bless $self, $class; } sub describe { my $self = shift; my $str = $self->SUPER::describe (); return $str . <<"desc"; My colour is $self->{colour}. desc } package main; my $car = new Car; print $car->describe ();

Prints:

My engine is 1800cc. I have 4 wheels and 4 doors. My colour is blue.

Although actually that is still pretty nasty. Consider what would happen if you needed a bike: no engine and no doors, or even worse a monocycle with only one wheel ("I have 1 wheels and 0 doors.").

A good starting point for some of this stuff is perlboot, but take a look around the Tutorials area too.


DWIM is Perl's answer to Gödel

In reply to Re: Hash from package by GrandFather
in thread Hash from package by Yoda_Oz

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.