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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |