Ron Bergin wrote: > Others have already pointed what you were doing wrong, so I'll point out > something else. > > Instead of using 2 separate split statements, I'd use a single split > statement to assign $state and a @zipcodes array. > > use 5.010; > use strict; > use warnings; > use Data::Dumper; > > my %entries; > > while (my $line = <DATA>) { > chomp $line; > my($state, @zipcodes) = split /[=,]/, $line; > push @{ $entries{$state} }, \@zipcodes;
I kept your original hash data structure, but in this case I think we should simplify it a bit. $entries{$state} = \@zipcodes; > } > > foreach my $state (sort keys %entries) { > say "The Zip Codes of $state are"; > say Dumper $entries{$state}; > } > > > __DATA__ > AK=995,996,997,998,999 > CA=95122,95035,95112 > > ----------- > > Outputs: > The Zip Codes of AK are > $VAR1 = [ > [ > '995', > '996', > '997', > '998', > '999' > ] > ]; > > The Zip Codes of CA are > $VAR1 = [ > [ > '95122', > '95035', > '95112' > ] > ]; > > -- > Ron Bergin > -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/