On Monday, July 8, 2002, at 05:05 , Jose Malacara wrote: [..] > State=Colorado > City=Denver > City=Boulder > City=Longmont > State=Texas > City=Austin [..] > This is what I would like the end result to be: > > State=Colorado > City=Denver > Location=DenverColorado
there are several ways to attack this problem - but the first thing I like to do is look at the data from what we starts to glow.[1] given that you are essentially triggering an event at two places: a) when we detect a 'state' b) when we detect a 'city' but in the main we essentially print every line. assume for the sake of the drill that we have all the input in an @list so we can get it out with the basic 'for loop' structure. We will need to have an 'external variable' that will be able to carry data from one line to the next and so we have my $current_state; for (@list) { print "$_ \n"; # # solve the state problem here # } well here we bring in our friend split my ($key, $val) = split(/=/); if ($key =~ /State/ ) { $current_state = $val; elsif ($key =~ /City/) { print "Location=${current_state{${val}\n"; } else { # ok, so I was BORN PARANOID die "neither state nor city with $key, $val\n"; } the put it together bits with some other ideas are at http://www.wetware.com/drieux/pbl/perlTrick/HA/growList.txt ciao drieux --- [1]ok, so maybe watching 'beautiful minds' was not a 'safe' experience... -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]