gaurav_chetal has asked for the wisdom of the Perl Monks concerning the following question:

I have two tab-delimited files "1.txt" and "2.txt". The structure of both the files is :
1st file : Main_File1 Start End 1 200 250 2 310 340 2nd file : Main_File2 Start End 1 200 250 2 350 370

I want to write a perl code for which the output should be two files i.e. one file having the list of common "start" and "end" positions and other file having unique "start" and "end" positions. From what I have read there will be use of hashes in this.Kindly help.

Replies are listed 'Best First'.
Re: Perl File Column Comparison.
by Anonymous Monk on Jan 25, 2014 at 08:50 UTC
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Perl File Column Comparison.
by Laurent_R (Canon) on Jan 25, 2014 at 18:28 UTC
    Read the first file and create a hash where the keys will be the concatenation of start and end values, separated by some separator and the value might be the first column of your file if you need it. In the case of your example, this could give this hash:
    ('200-250' => 1, '310-340' =>2);
    Then you read the second file line by line, build the keys the same way and check if the interval was in the first file. If you find it, output the line to the file of common values, and delete that element from the hash. If not found, output the line to the orphans2 file (file of intervals in the second file but not in the first). At the end of the process, the hash contains the orphans1 (intervals existing in the first file but not in the second).