This is what you are doing:

If we take 2 files like so:
/tmp/file1
1
2
3
4

/tmp/file2
a
b
c
d
e

We'd get these results using your code:
outer loop $_= 1
inner loop $_= a
inner loop $_= b
inner loop $_= c
inner loop $_= d
inner loop $_= e
outer loop $_= 2
outer loop $_= 3
outer loop $_= 4
What we see is that the inner loop isn't working... care to know why? You need to open and close the inner file. Otherwise file2 is not set to the start again after each search, it will be EOF for subsequent loops. The $_ are fine,

I would recommend using foreach rather than while, and if the files are small enough why not load the files into arrays and drive the comparison off them? If the files are of a size and the computer you're using is of a low power, think about using a sorted file and a binary chop and index the search file, just a thought... The O'Reilly Wolf book or the Perl Cookbook are great places to look for examples.

Hope this helps...

--
Brother Frankus


In reply to Less whiles more wiles :^) by frankus
in thread Double While! by Anonymous Monk

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.