Re: Hash problem
- From: krahnj@xxxxxxxxx (John W. Krahn)
- Date: Thu, 28 Sep 2006 13:47:30 -0700
Johnson, Reginald (GTI) wrote:
I am doing an example from Perl Objects, References & modules. I suspect
many of you already use this book as a reference.
My hash is showing the address instead of the name and I'm not sure
why. Here is my output.
this is person=>HASH(0x20040014)
this is who=>HASH(0x20040014)
HASH(0x20040014) is missing preserver
HASH(0x20040014) is missing sunscreen
HASH(0x20040014) is missing water_bottle
HASH(0x20040014) is missing jacket
Here is the code
#!/usr/bin/perl
use warnings;
use strict;
my @gilligan = qw(red_shirt hat lucky_socks water_bottle);
my @skipper = qw ( blue_shirt hat preserver sunscreen);
my @professor = qw(sunscreen water_bottle slide_rule batteries
radio);
my %all = {
"Gilligan" => \@gilligan,
"Skipper" => \@skipper,
"Professor" => \@professor,
};
If you had included the warnings pragma then perl would have told you what is
wrong:
Reference found where even-sized list expected at Hash_problem.pl line 8.
You need to assign a list to %all, not an anonymous hash:
my %all = (
Gilligan => \@gilligan,
Skipper => \@skipper,
Professor => \@professor,
);
John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
.
- References:
- Hash problem
- From: Reginald Johnson
- Hash problem
- Prev by Date: Re: please advise help with regex
- Next by Date: Re: --compare current date file with previous day
- Previous by thread: Re: Hash problem
- Next by thread: RE: Hash problem
- Index(es):
Relevant Pages
|