Hi Monks,
I need help in this range finding stuff. My foreach loop is not working correctly. My input looks like this
5893 5985 + LOC645399 645399 7223 7231 - LOC100131533 100131533 7630 9882 - LOC100131533 100131533 10142 11428 + LOC100132836 100132836 12197 13705 - LOC100132070 100132070 14248 15806 - LOC100132865 100132865 16830 17405 - LOC100132865 100132865 18735 19817 + LOC645399 645399 20802 23113 - LOC100132865 100132865
My code is:- $fn = $ARGV[0]; open(FH, "$fn") || die("Cannot open: $!"); for ($i = 5893; $i <=23113; $i++) { $bin = $i += 7704; push @array, $bin ; } while(<FH>) { if($_ =~ /\A(\S+)\s+(\S+)/) { foreach $line(@array){ print "$line\n"; print "$1 $2\n" if $line >= $1 && $line <= $2; } } }
As per above example my array contains values :- 13597,21302, 29007 which is by 3 division of the maximum value 23113 which means a bin size of 3 with size 7704 per bin and then I am trying where my array values fit as per given ranges in my input data.
I expect my output to come something like this in bin range range specified by my first for loop:-
12197 13705 20802 23113
My foreach loop has got a problem. It prints the value multiple times and also my 2nd if condition is not taking the values.
Thanks in advance

In reply to Problem in Foreach loop by cowboyrocks

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.