On Tue, 25 Sep 2001, aurillo, gabriel wrote:

> I have an array, as follows:
>
> @allLines = (
>       "line1 = value1",
>       "line2 = value2",
>       "line3 = value3",
>       "!line4 = value1",
>       "!line5 = value2",
>       "!line6 = value3",
>       "line7 = value7",
>       "line8 = value8",
>       "line9 = value9",
>       "line10 = value10"
> ) ;
>
> How do I loop through each line with the following criteria:
> If the line starts with a bang (!) AND the value has already
> been "seen", skip that line AS WELL AS the line previously
> seen. In this case, the remaining list should only have lines
> 7 to 10 because line 4 starts with a bang AND the value is
> equal to the value of line 1. And so on...

In the first place, why use an array here?  This looks like a prime
candidate for a hash!  In fact, you could flip this: use the value column
as your hash keys, and the line column as the hash values, you can check
to see if the key already has a value associated with it, and then delete
the element if it does.  So if you are going along and get to the 4th
line, you will see that the element with key 'value1' has been defined as
'line1', so you know this line and value (which is the key) has already
been seen, so you can just delete it.  It's kind of backwards, but it will
save you some text parsing.

-- Brett
                                          http://www.chapelperilous.net/
------------------------------------------------------------------------
The future is a myth created by insurance salesmen and high school counselors.


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

Reply via email to