http://qs1969.pair.com?node_id=193438

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have a program that needs to process a list as a FIFO so I have written it as...
foreach my $item (@list) {
   ... code
}
however the code inside the loop is appending new information to the end of the list but I want to avoid duplicate entries so I'm having to loop over the list to check if the new item isn't already in the list. The program is, obviously, getting slower the longer the list gets.

So I should use a hash to do the lookup, but a hash cannot be extended within the outer loop.
while(my($item, $ummy) = each(%hash)) {
   ... code
}
only processed the values that were in the hash when it was created and ignores those that are being added as the code is run.

It looks like I need to use both a list so that I can process all the items and a hash to speed up the lookup. Is there another way?