pem@frankland-river.aaii.oz.au (Paul E. Maisano) (03/02/90)
Either I am doing something totally stupid or this is a mean bug. If it is a bug and has been mentioned before, I apologize. I don't recall any mention of this one. This program does a double loop collecting all elements from the first list which do not occur in the second list. Simple. -----cut here----- #!/usr/bin/perl @source = (1, 1, 2, 3, 4); @list = (1, 3, 4); # make a new list consisting of @source without the numbers in list @new = (); source: foreach $s (@source) { print "next s: $s, search (@list)\n"; foreach $t (@list) { print "compare: $s with $t\n"; next source if $t == $s; } push(@new, $s); print "push $s: new = (@new)\n"; } print "new = (@new)\n"; -----cut here----- I would have expected a result of "new = (2)". Here is the output: (on a sparcstation1/perl 3.0 pl8) next s: 1, search (1 3 4) compare: 1 with 1 next s: 1, search (1 3 4) compare: 1 with 3 <<<< Why did it skip the first element? compare: 1 with 4 push 1: new = (1) next s: 2, search (1 3 4) compare: 2 with 1 compare: 2 with 3 compare: 2 with 4 push 2: new = (1 2) next s: 3, search (1 3 4) compare: 3 with 1 compare: 3 with 3 next s: 4, search (1 3 4) compare: 4 with 4 new = (1 2) I probably need patch-9. I'll just recode it some other way for now. ------------------ Paul E. Maisano /\ /\ // // Australian Artificial Intelligence Institute //\\ //\\ || || 1 Grattan St. Carlton, Vic. 3053 // \\ // \\ || || Ph: +613 663-7922 Fax: +613 663-7937 // \\ // \\ || || Email: pem@aaii.oz.au ///// \\ ///// \\ || || UUCP : {uunet,mcsun,ukc,nttlab,ubc-cs}!munnari!aaii.oz.au!pem