HoA question
- From: cajun@xxxxxxxxxxxx ("M. Lewis")
- Date: Thu, 28 Dec 2006 20:20:46 -0500
I'm still experimenting with the HoA from a couple of days ago. I just realized there is the possibility for having duplicate elements of the array. How do I prevent that?
Thanks,
Mike
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper::Simple;
my %HoA;
while (my $line = <DATA>){
chomp $line;
my ($prod, $flavor) = split ' ', $line, 2;
push @{ $HoA{ $prod } }, $flavor;
}
for my $i ( keys %HoA ) {
print "$i -- @{ $HoA{$i} }\n";
}
warn Dumper (\%HoA);
__DATA__
jelly strawberry
jelly apple
jelly pear
jelly grape
jelly pear
jam strawberry
jam apple
jam apple
jam grape
milk plain
milk chocolate
milk strawberry
--
If I had it all to do over again, I'd spell creat with an "e". - Kernighan
20:15:01 up 14 days, 17:06, 0 users, load average: 0.09, 0.29, 0.25
Linux Registered User #241685 http://counter.li.org
.
- Follow-Ups:
- Re: HoA question
- From: "John W. Krahn"
- Re: HoA question
- Prev by Date: Re: perl extracting substrings from string
- Next by Date: Re: HoA question
- Previous by thread: perl extracting substrings from string
- Next by thread: Re: HoA question
- Index(es):