A few days ago I was very kindly helped with writing a program to replace certain values in a long string of characters, as seen here here. I've attempted to modify and to use the program with short test files as shown below to change al characters outside my intervals to 'N', but the values changed are not consistent with the program's goal. Can anyone see an error in the code?

INPUT FILE: 0000000000 ------------- INTERVALS: chrX 1 3 chrX 5 6 chrX 8 9 ------------ DESIRED OUTPUT FILE: 000N00N00N ----------------- OUTPUT FILE: N00NNNNNNN ---------------- CODE: #!/usr/bin/perl -w use strict; use warnings; my $population = "test"; open( INPUT, "</Users/logancurtis-whitchurch/Desktop/test.mask.txt") o +r die "can't open masked file\n"; open( OUT, ">/Users/logancurtis-whitchurch/Desktop/filtered.test.mask. +txt") or die "can't open output file\n"; my $mask_input = <INPUT>; close INPUT; my $filtered_sites = "/Users/logancurtis-whitchurch/Desktop/test.inter +val"; open (INTERVAL, "<$filtered_sites") or die "can't open $filtered_sites +"; my $lastEnd = 1; while ( <INTERVAL> ) { my (undef, $start, $end) = split '\s', $_; ## change everything from the end of the last range ## to the start of this range to 'N' substr( $mask_input, $lastEnd, $start ) =~ tr[\x00-\xff][N]; $lastEnd = $end; } close INTERVAL; ## change everything from the end of the last range to the end of stri +ng to 'N' substr( $mask_input, $lastEnd, length( $mask_input ) ) =~ tr[\x00-\xff +][N]; print OUT "$mask_input";

In reply to Trouble with Transliterate Function 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.