utpalmtbi has asked for the wisdom of the Perl Monks concerning the following question:
Hi all,
I am trying to check intermediate range values from two file columns.
My two input files are like this:
(file1.txt)
a 11-23
b 33-39
c 40-45
d 48-58
& (file2.txt)
33-39
40-42
43-46
51-52
From it, I want to match the file2 values to that of file1 (2nd column) with intermediate ranges of values, I want the output to be like:
b 33-39
c 40-42, 43-45
d 45-46, 51-52
I have tried:
@ARGV or die "No input file specified"; open my $first, '<', $ARGV[0] or die "Unable to open input file: $!"; open my $second, '<', $ARGV[1] or die "Unable to open input file: $!"; print scalar(<$first>); my $secondHeader = <$second>; while (<$first>) { @cols = split /\s+/; $p1 = $cols[1]; $p2 = $cols[2]; my $secondLine = <$second>; if ( defined $secondLine ) { @sec = split( /\s+/, $secondLine ); print join( "\t", @cols ), "\n" if ( $p1>=$sec[0] && $p2<=$sec +[1] || $p1<=$sec[0] && $p2>=$sec[1] ); } }
Which gives me wrong output:
a 11-23
b 33-39
c 40-45
d 46-58
I am stuck about what argument I should give in the last line to get the proper output.. Plz help
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: finding intermediate range values from two file columns
by choroba (Cardinal) on Aug 09, 2016 at 21:03 UTC | |
|
Re: finding intermediate range values from two file columns
by haukex (Archbishop) on Aug 09, 2016 at 21:07 UTC | |
by Anonymous Monk on Aug 09, 2016 at 23:45 UTC | |
|
Re: finding intermediate range values from two file columns
by perldigious (Priest) on Aug 09, 2016 at 19:59 UTC | |
by perldigious (Priest) on Aug 09, 2016 at 21:45 UTC | |
|
Re: finding intermediate range values from two file columns
by Anonymous Monk on Aug 10, 2016 at 14:19 UTC |