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


In reply to finding intermediate range values from two file columns by utpalmtbi

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.