in reply to Use of Uninitialized in Concatenation or String Error?
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Use of Uninitialized in Concatenation or String Error?
by ccelt09 (Sexton) on Aug 09, 2013 at 11:10 UTC | |
by Laurent_R (Canon) on Aug 09, 2013 at 12:56 UTC | |
by ccelt09 (Sexton) on Aug 09, 2013 at 14:55 UTC | |
by Laurent_R (Canon) on Aug 09, 2013 at 17:56 UTC |