The main issue really was that you provided an end position to substr while it expects a length. This has already been corrected by choroba above. I would like to propose to directly construct the intervals for the Ns under the assumption that your input intervals are sorted and non-overlapping. So instead of looking at 1 => 3, 5 => 6, etc I propose to add a zero at the beginning and the length of the string at the end to get 0 => 1, 3 => 5, 6 => ... which give you directly the intervals to put Ns into.
use warnings; use strict; my $mask_input = '0000000000'; my %intervals = ( 0, ( do { local $/; <DATA> } =~ /(\d+)/g ), 1+length + $mask_input ); while( my( $start, $end ) = each %intervals ) { substr( $mask_input, $start, $end-$start-1 ) =~ tr/N/N/c; } print "$mask_input\n"; __DATA__ chrX 1 3 chrX 5 6 chrX 8 9
In reply to Re: Trouble with Transliterate Function
by hdb
in thread Trouble with Transliterate Function
by ccelt09
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |