in reply to Please help, (perl hash)
What the other respondents have said, except that you...
would like the street to be the key (so that it is easy to loop through, and from that point, i can get the town and the number of houses)...
so I would organize the data a bit differently. There is an Oak street in Oakdale city, a Pine street in Pinehill city, and both cities have a Main street.
>perl -wMstrict -le "my %streets = ( Oak => { Oakdale => 23 }, Pine => { Pinehill => 45 }, Main => { Oakdale => 67, Pinehill => 89, }, ); ;; for my $street (keys %streets) { for my $city (keys %{ $streets{$street} }) { printf qq{%s street in %s city has %d houses \n}, $street, $city, $streets{$street}{$city}; } } " Oak street in Oakdale city has 23 houses Pine street in Pinehill city has 45 houses Main street in Pinehill city has 89 houses Main street in Oakdale city has 67 houses
|
|---|