If one has an array can you assign the length of its current index value from the beginning to a scalar variable?

Essentially I am reprinting a text file made of one long string of 0's and N's with no spaces. At the positions along this string that lie outside of certain intervals, I want all the elements reprinted as N's.

input file looks like this: 0000000NNNN00NNN0NNN0N0N0NN0N #------------------------------------------------- my $population = "all28_males"; my $count = 0; my $position = 0; my ($n, $data, @info, $info, $buf); my $filtered_sites = "/Users/logancurtis-whitchurch/Dropbox/thesis_fol +der/galaxy_chrX_data/filtered_chrX_rawdata.interval"; open (INTERVAL, "<$filtered_sites") or die "can't open $filtered_sites +"; open(MASK, "/Users/logancurtis-whitchurch/Dropbox/thesis_folder/consen +sus_files/filtered_mask_files/filtered.mask."."$population".".txt") o +r die "can't open masked file\n"; my $mask = <MASK>; chomp ($mask); for each (my @interval = <INTERVAL>); { chomp (@interval); my @positions = split(/\t/, $interval[$count]); my $start = $positions[1]; my $end = $positions[2]; while (($n = read MASK, $data, 100000) != 0) { my @info = split(//, $data); my $length = 1; foreach $info (@info){ if ( $length < $start]) { substr($mask,($info),1,'N'); $length++; } if (( $length >= $start) && ($length <= $end)) { next; $length++ } if ($length > $end) { $count++; } } $buf .= $data; print OUT "$mask"; close OUT; close MASK; } }

In reply to A question About Array Indexing 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.