Hi ccelt09,

In truth I couldn't quite work out what your code was trying to do. But your description of what you wanted to accomplish seemed clear. Below is a different take on how to sort your input into separate files. It could be easily done with fewer CPAN modules, but I reached for them anyway. So to use this code you'd have to install the following from CPAN:

 Text::CSV_XS DBI DBD::CSV

If that's not a problem, then the following code should work well for you:

use strict; use warnings; use Text::CSV; use DBI; # input filename, and output file template with %d for interval # my $input_filename = 'td.data'; my $output_filename = 'split_%d.data'; # Divide loci into groups of one million per output file sub calculate_interval { return int((shift) / 1000000) }; my $dbh = DBI->connect ("dbi:CSV:", undef, undef, { csv_eol => "\n", csv_sep_char => "\t", csv_class => "Text::CSV_XS", csv_null => 1, csv_tables => { genetics => { f_file => $input_filename,, col_names => [qw(a b c d locus f g h i j k l m n o)], }}, RaiseError => 1, PrintError => 1, }) or die $DBI::errstr; # Magic my $sth = $dbh->prepare("select * from genetics order by locus"); $sth->execute; # Grunt work to output into separate files $, = "\t"; my $output; my $output_interval = -1; while (my @row = $sth->fetchrow_array) { my $interval = calculate_interval $row[4]; if ($interval ne $output_interval) { $output_interval = $interval; open $output, '>', sprintf($output_filename, $interval) or die "$output_filename $!"; } print $output @row, "\n"; }
With this input data in a file named td.data:
0 50 4 46 723430 0 2 1 2 1 1 1 1 + 3 1 0 50 4 46 5533723430 0 2 1 2 1 1 1 + 1 3 1 0 50 4 46 33723430 0 2 1 2 1 1 1 1 + 3 1 0 50 2 48 654732 0 1 1 1 0 2 3 2 + 1 3
This was the result:
split_0.data:0 50 2 48 654732 0 1 1 1 0 +2 3 2 1 3 split_0.data:0 50 4 46 723430 0 2 1 2 1 +1 1 1 3 1 split_33.data:0 50 4 46 33723430 0 2 1 2 1 + 1 1 1 3 1 split_5533.data:0 50 4 46 5533723430 0 2 1 2 + 1 1 1 1 3 1

In reply to Re: Use of Uninitialized in Concatenation or String Error? by Loops
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.