Hi,

I am not sure that it will work on every system, but I was able to create on my system an array of 155 file handlers. Then, I only need to read the input data, find out in which range the line should be output and print it to the right fila handler. Thus, no need to sort the data.

use strict; use warnings; use integer; no strict "vars"; my @FH; for my $i (0..154) { my $file = "file$i" . ".txt"; open $FH[$i], ">", $file or die "could not open $file $!\n"; my $fh = $FH[$i]; print $fh "File number $i \n"; } while (<DATA>) { my $locus = (split /\t/, $_)[4]; my $range_nr = $locus / 1e6; warn "out of range: $_" and next if $range_nr > 154; my $fh = $FH[$range_nr]; print $fh $_; } close $FH[$_] for (1..154) __DATA__ 0 50 2 48 654732 0 1 1 1 0 2 3 2 + 1 3 0 50 4 46 1723430 0 2 1 2 1 1 1 1 + 3 1 0 50 2 48 14654732 0 1 1 1 0 2 3 2 + 1 3 0 50 4 46 7723430 0 2 1 2 1 1 1 1 + 3 1 0 50 2 48 2654732 0 1 1 1 0 2 3 2 + 1 3 0 50 2 48 2654733 0 1 1 1 0 2 3 2 + 1 3 0 50 2 48 2654734 0 1 1 1 0 2 3 2 + 1 3 0 50 2 48 2654735 0 1 1 1 0 2 3 2 + 1 3 0 50 2 48 2654736 0 1 1 1 0 2 3 2 + 1 3 0 50 4 46 6723430 0 2 1 2 1 1 1 1 + 3 1

Content of file2.txt:

File number 2 0 50 2 48 2654732 0 1 1 1 + 0 2 3 2 1 3 0 50 2 48 2654733 0 1 1 1 + 0 2 3 2 1 3 0 50 2 48 2654734 0 1 1 1 + 0 2 3 2 1 3 0 50 2 48 2654735 0 1 1 1 + 0 2 3 2 1 3 0 50 2 48 2654736 0 1 1 1 + 0 2 3 2 1 3

In reply to Re: Use of Uninitialized in Concatenation or String Error? by Laurent_R
in thread Use of Uninitialized in Concatenation or String Error? by ccelt09

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.