in reply to Reqex from two files and compare

Aersol's plan was very much on the mark (++), and while he wanted you to work out the rest, I thought I would suggest one alternative that might simplify things a bit, and allow you to use multiple entries for the same perl file in the "changes.txt" listing. Where aersol had this:
# is it a range or a single line? if ($info =~ /(\d+)-(\d+)/) { $changes{$file} = [$1, $2]; } else { $changes{$file} = [$info]; }
you could have this instead:
if ($info =~ /(\d+)-(\d+)/) { $changes{$file} .= " ".join(" ",($1 .. $2))." "; } else { $changes{$file} .= " $info "; }
This way, each value in %changes is a string of space-separated line numbers, including every line that has changed in a given file, and by using ".=", the string just gets longer each time the same file is mentioned again in changes.txt. Now, when you check this against the "data.txt" listing, instead of aersol's two-way test, you have a single test for all cases:
... if (defined $changes{$file}) { # skip if this $line isn't mentioned in $changes next unless ($changes{$file} =~ / $line /); } ...

Replies are listed 'Best First'.
Re: Re: Reqex from two files and compare
by DS (Acolyte) on Jul 17, 2002 at 05:03 UTC
    nice one ;) , ,, thanks