Hello Monks, me again. I am sorry to be bothering you again! I am trying to compare a list of two indexes the first (var1) being 1000~ enteries long and the second(var2) ~70 enteries long. A simple task i thought. I wish (at this stage) just to print indexs occuring once in var1 and once in var2.
@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 { } } }
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

Code edit per author - dvergin 2003-08-11


In reply to Compare two index lists by pdotcdot

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.