in reply to Hash from package
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.use strict; use warnings;
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:
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.foreach my $key (keys %$hash_ref) { print "I have $key $hash_ref->{$key}\n"; }
Good luck.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Hash from package
by Yoda_Oz (Sexton) on Jan 04, 2007 at 09:43 UTC |