The copy of @var (lines 2 and 5) is needed as before this was created the loop only ever ran through once, as the original array had been deleated. (ASIDE Is this a side effect due to scoping?i am using strict, and declare my variables at the start of the program ). The problem. The above code only ever returns the first matched value , not the list of matched values. I have checked via print statements (see code) that each value of var2 is compared to each value of var1. I have double checked the input data has correct format (ie no spaces/newlines were they should not be, no multiple occurences of any value in either set). I have used different methods of looking for a match.(eq, ==, /^var2$/). I have placed a different variable than the first var2 into the "if statement" line, this returns correct match from var1, so i know that match principle works. Apologies for the rant, i was just trying to make this problem clearer, many thanks in advance. PC@var2=<INPUT>; @copyvar2=@var2; foreach $var1 (@var1){ print "OUTER LOOP OK $var1\n"; @copyvar2=@var2; foreach $var2 (@var2) { print "INNER LOOP OK $\n"; chomp $var1; # was: chomp $headers; chomp $var2; # was: chomp $matched; if ($var1=~/$var2/){ print "$var1\.\.$var2\n"; } else { } } }
Code edit per author - dvergin 2003-08-11
In reply to Compare two index lists by pdotcdot
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |