while (<$in_file>) { chomp; if (/^SAMPLE/) { my ( $placeholder, @coords ) = split /,/; foreach my $coord (@coords) { push @snp_bins, int( $coord / 100_000 ); } } else { my ( $id, @snps ) = split /,/; foreach my $snp (@snps) { # (@snps[0..$#snps-1] $snp =~ s/$snp/$snp,/ # put commas back in (preserve csv format) } foreach my $index ( 0 .. $#snp_bins ) { if ( $snps[$index] ) { push( @{ $data{$id}[ $snp_bins[$index] ] }, $snps[$index] ); # see note [1] } else { # replace 'undef' elements with flag data my @ones_array; foreach ( 1 .. 100) { push @ones_array, "1 1,"; } push( @{ $data{$id}[ $snp_bins[$index] ] }, @ones_array ) } } } } #### if ( $snps[$index] )