At 05:04 PM 6/16/01 -0400, F.H wrote:
>Hi All,
>I am trying to display some data as follows:
>
> City: Chicago
> Street: Main
> People:
> John Doe 1
> John Doe 2
> J.D 3
>
> City: L.A
> Street
> and so on...for the other states
>my %state;
>While ($line = <INPUT>){
>...
>push @{$state{$city}{$street}{people}}, @line[5..$#line];
>
>}
>Now the problem:
>foreach $city (keys %state) {
>print" City: $city\n";
> foreach $i (0 .. $#{$state{$city}{$street}}{
> print" Street: $street\n";
>
> foreach $j (0 .. $#{$state{$city}{$street}{people}{
> print" $_\n";
>}
>}
>}
>This is where I get stuck. I'd appreciate if someone can help.
Some kind of C heritage is showing. You're not showing where $street is
coming from, either.
foreach my $city (keys %state) {
print "City: $city\n";
foreach my $street (keys %{$state{$city}}) {
print "\tStreet: $street\n";
foreach my $person (@{$state{$city}{$street}{people}}) {
print "\t\t$person\n";
}
}
}
See how that just looks like what you had to begin with? BTW, that
"people" key is redundant, unless you have other keys at that level.
--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com