Given the simplicity of what you want to compare, your code seems to me to be far too complicated. I don't feel like dwelling into your code, but, setting aside the HTML output, I feel the whole comparison part could probably be done in less than 20 lines of code. But you don't really state what you want to do.

An important question: how large are your files? Reading the complete second file for each line of input in the first file is most probably extremely inefficient. One of the most common way to do this type of thing is to store one of the files (often the smallest one, but not necessarily) in an appropriate data structure, often a hash or something similar, so that you can then read the other file line by line and access instantly to the data you need for the comparison. But this is not possible if your files are really huge and will exhaust memory.

If the files are really too large for that (i.e. the file won't fit into memory), there is still another possibility: sort both files according to the comparison key, and read them in parallel.

But don't read one file for each input line of the other. This is extremely inefficient.


In reply to Re: open and read file using cgi perl by Laurent_R
in thread open and read file using cgi perl by vivek.vivek

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.