Yes, you found the problem. A simple approach could be to use a copy of @lines to modify and then execute. That way you would still have the original @lines around for the next round.
Why do you think that share() or lock() come into play? Is the problem related to threads? Did you check that? You can easily switch your program into single-threaded mode. Does the error persist?
Note that these are all rhetorical questions for me - they are intended to guide you in the process of debugging and eliminating all other possible causes.
|