Hi. First things first. You really always want to have:
use strict; use warnings;
as the first lines of your script. It'll help eliminate false alarms when looking for problems like this, and it is much easier to always start with it in then try and add it in later.

If you do that, you'll see that perl wants you to write the hash accesses as $foo->{'bar'}, not %{$foo}->{'bar'}. You'll also see that you want to have our @ISA = ('Vehicle'); I think those are the only things it throws up.

As for your question, $hash_ref->{$key} is an expression for the value you get when looking up the key in the hash. It doesn't return the key itself, but then again, you don't need that since you've just used the key to look up in the hash, so you'll always have it to hand.

If you want to print keys and values, do you'll need to do it explicitly:

foreach my $key (keys %$hash_ref) { print "I have $key $hash_ref->{$key}\n"; }
Lastly, if you're doing OO in perl, you might want to use one of the (too many) helper modules, such as Class::Accessor or Moose. Also, rather than setting @ISA directly, I find use base qw(Vehicle); a nicer way to express inheritance in perl.

Good luck.


In reply to Re: Hash from package by jbert
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.