[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] perl infinite loop? -- array comparison



I'm trying to write a Perl script to automate the updating of a flat text 
file database. I'm trying to compare the new database of titles to the 
old databse of titles and get a list of "Brand New Titles."

Everything goes fine up untill the following chunk of code where the 
actual comparison is supposed to happen. When the script gets to this 
point it gets stuck and just spins its wheels. Is there an infinite loop 
here? Is there a more efficient way to do this?

while (@new_titles)
{
	$i = shift (@new_titles);				     # grab the title on the top
	
	$j = 0;
	
	foreach $k (@old_titles)			       # compare the new title to each of the 
old titles
		{
		if ($i eq $k)					               # untill we find a match
			{
			splice (@old_titles, $j, 1);    # remove the matched title from the 
old titles list	
			last;							                    # so we don't check it again and stop 
looking
			}
		elsif ($#old_titles < 1)			      # but if we're at the end of the list 
of old titles
			{								                       # then we found a brand new title 
			push (@brand_new_titles, $i);		 # so we push it onto brand_new_titles
			}
		else								                     # if we don't find a match 						
			{	
			$j++;							                    # increment the counter and keap 
looking
			}	
		}
}	


***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch