At 06:05 PM 7/8/2002 -0600, Jose Malacara wrote:
>Hello all,
>I am new to the list and have what I believe is a pretty basic question, 
>I'm just not sure where to begin.
>
>I have a file where I need to search for the occurences of two variables 
>(State and City) and then create another field (Location) based on the sum 
>of the two previous values. I was wonderig if someone could recommend a 
>method to do this? I don't mind hashing it out myself if someone might 
>point me in the right direction.
>
>This is basically what I have now:
>
>State=Colorado
>City=Denver
>City=Boulder
>City=Longmont
>State=Texas
>City=Austin
>City=Dallas
>City=Houston
>
>
>This is what I would like the end result to be:
>
>State=Colorado
>City=Denver
>Location=DenverColorado
>City=Boulder
>Location=BoulderColorado
>City=Longmont
>Location=LongmontColorado
>State=Texas
>City=Austin
>Location=AustinTexas
>City=Dallas
>Location=DallasTexas
>City=Houston
>Location=HoustonTexas
>
>I guess my main question would be how to keep the 'State' value associated 
>with the cities that follow it.
>


Sounds like the right place for a hash of arrays.  Let your keys be the 
states and your values be anonymous arrays of cities.  Like so:

         %sites =   (    'Colorado'      =>      [ qw(Denver Boulder) ],
                         'Texas'         =>      [ qw(Austin Dallas 
Houston) ]   );

I'd build the Location field only as I needed it for printing.

foreach $state (sort keys %sites) {
         foreach $city (sort @{ $sites{$state} }) {
                 print "Location = $city$state\n";
         }
}

Cheers,
Kristina Nairn




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to