Hello,

First of all, it would be easier to help you by showing things on the code you have written. Please keep this in mind when asking questions, because people usually want to see that you have at least tried.

If I were you, I would iterate thru the lineChanges.txt first, and store the parsed data into a hash. Example:

while (<CHANGES>) { chomp; # split the line from the spaces my ($file, $info) = split(/\s+/, $_, 2); # is it a range or a single line? if ($info =~ /(\d+)-(\d+)/) { $changes{$file} = [$1, $2]; } else { $changes{$file} = [$info]; } }

(At this point you may want to look at what you have parsed so far. Try Data::Dumper.)

Now you have to check for each line of data.txt in this hash. You may do it like this:

while (<DATA>) { chomp; # split the line from the wave characters my ($file, $line, $type, $rest) = split(/~/, $_, 4); # was this file found in the previous loop? if (defined $changes{$file}) { # was it a range? if (defined $changes{$file}->[1]) { # skip if this $line is not in this range next unless ($line gt $changes{$file}->[0] and $line lt $changes +{$file}->[1]); } else { # skip if this $line is not equal to this single line number next unless $line eq $changes{$file}->[0]; } # if we are here, then this is a match. so print it. print "$_\n"; } }

There are issues with this approach. For example, in your lineChanges.txt, there are two you.pl lines. The second one will overwrite the first one, because of the same file name being used as the hash key. You may overcome this by: 1- using a different storage method, 2- changing the order of the loops (ie. parsing data.txt into a hash). I leave this as an exercise to the reader.

I hope this helps a bit.

--
Alper Ersoy


In reply to Re: Reqex from two files and compare by aersoy
in thread Reqex from two files and compare by DS

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.