The following modification of the code I posted in reply to your Complex Data Structure thread should probably do the trick:

use strict; use warnings; my $data = <<DATA; CLS_S3_Contig100_st,CLS_S3_Contig100,13,10,0.3717 CLS_S3_Contig100_st,CLS_S3_Contig100,53,10,0.3717 CLS_S3_Contig10031_st,CLS_S3_Contig10031,53,12,0.5548 CLS_S3_Contig10031_st,CLS_S3_Contig10031,57,10,0.4871 CLS_S3_Contig10031_st,CLS_S3_Contig10031,61,12,0.547 CLSS3627.b1_F19.ab1,CLS_S3_Contig10031,62,11,0.5129 CLSS3627.b1_F19.ab1,CLS_S3_Contig10031,64,11,0.5789 DATA my %origins; my $numColumns; open my $inFile, '<', \$data; while (<$inFile>) { chomp; next unless length; my @columns = split ','; $numColumns ||= @columns; # Assume first row has correct column co +unt $origins{$columns[1]}[$columns[2] - 1] = \@columns; } close $inFile; for my $oKey (sort keys %origins) { my $origin = $origins{$oKey}; my $lastAdded = -1; # Fake up present flag for +/- 8 lines around real data for my $pip (0 .. $#$origin) { next if $pip <= $lastAdded or ! defined $origin->[$pip]; my $first = $pip > 8 ? $pip - 8 : 0; my $last = $pip + 8; $last = $#$origin if $last > $#$origin; for my $index ($first .. $last) { next if defined $origin->[$index]; @{$origin->[$index]}[0 .. $numColumns - 1] = ('', $oKey, $index + 1, ('') x $numColumns); } $lastAdded = $last; } # Now output the result for my $pip (0 .. $#$origin) { my $row = $origin->[$pip]; if (defined $row) { # pip exists in original file print join (",", @$row, '1'), "\n"; } else { # pip doesn't exist in original file print ",$oKey,", $pip + 1, ',' x ($numColumns - 2), "0\n"; } } }

Prints:

... ,CLS_S3_Contig100,4,,,0 ,CLS_S3_Contig100,5,,,1 ,CLS_S3_Contig100,6,,,1 ,CLS_S3_Contig100,7,,,1 ,CLS_S3_Contig100,8,,,1 ,CLS_S3_Contig100,9,,,1 ,CLS_S3_Contig100,10,,,1 ,CLS_S3_Contig100,11,,,1 ,CLS_S3_Contig100,12,,,1 CLS_S3_Contig100_st,CLS_S3_Contig100,13,10,0.3717,1 ,CLS_S3_Contig100,14,,,1 ,CLS_S3_Contig100,15,,,1 ,CLS_S3_Contig100,16,,,1 ,CLS_S3_Contig100,17,,,1 ,CLS_S3_Contig100,18,,,1 ,CLS_S3_Contig100,19,,,1 ,CLS_S3_Contig100,20,,,1 ,CLS_S3_Contig100,21,,,1 ,CLS_S3_Contig100,22,,,0 ,CLS_S3_Contig100,23,,,0 ... ,CLS_S3_Contig100,43,,,0 ,CLS_S3_Contig100,44,,,0 ,CLS_S3_Contig100,45,,,1 ,CLS_S3_Contig100,46,,,1 ,CLS_S3_Contig100,47,,,1 ,CLS_S3_Contig100,48,,,1 ,CLS_S3_Contig100,49,,,1 ,CLS_S3_Contig100,50,,,1 ,CLS_S3_Contig100,51,,,1 ,CLS_S3_Contig100,52,,,1 CLS_S3_Contig100_st,CLS_S3_Contig100,53,10,0.3717,1 ,CLS_S3_Contig10031,1,,,0 ... ,CLS_S3_Contig10031,44,,,0 ,CLS_S3_Contig10031,45,,,1 ,CLS_S3_Contig10031,46,,,1 ,CLS_S3_Contig10031,47,,,1 ,CLS_S3_Contig10031,48,,,1 ,CLS_S3_Contig10031,49,,,1 ,CLS_S3_Contig10031,50,,,1 ,CLS_S3_Contig10031,51,,,1 ,CLS_S3_Contig10031,52,,,1 CLS_S3_Contig10031_st,CLS_S3_Contig10031,53,12,0.5548,1 ,CLS_S3_Contig10031,54,,,1 ,CLS_S3_Contig10031,55,,,1 ,CLS_S3_Contig10031,56,,,1 CLS_S3_Contig10031_st,CLS_S3_Contig10031,57,10,0.4871,1 ,CLS_S3_Contig10031,58,,,1 ,CLS_S3_Contig10031,59,,,1 ,CLS_S3_Contig10031,60,,,1 CLS_S3_Contig10031_st,CLS_S3_Contig10031,61,12,0.547,1 CLSS3627.b1_F19.ab1,CLS_S3_Contig10031,62,11,0.5129,1 ,CLS_S3_Contig10031,63,,,1 CLSS3627.b1_F19.ab1,CLS_S3_Contig10031,64,11,0.5789,1

Perl reduces RSI - it saves typing

In reply to Re: Hash_of_Hash_Would do it? by GrandFather
in thread Hash_of_Hash_Would do it? by sesemin

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.