http://www.perlmonks.org?node_id=1051328


in reply to Trouble with Transliterate Function

Seems like an off by one error. I tried to fix it:
#!/usr/bin/perl use warnings; use strict; my $mask_input = '0000000000'; my $lastEnd = 0; while (<DATA>) { my (undef, $start, $end) = split '\s+'; my ($from, $length) = ($lastEnd, $start - $lastEnd); $length-- if $length > 0; substr($mask_input, $from, $length) =~ tr[\x00-\xff][N]; $lastEnd = $end; } substr($mask_input, $lastEnd) =~ tr[\x00-\xff][N]; print "# Desired: 000N00N00N\n"; print "# Obtained: $mask_input\n"; print $mask_input eq '000N00N00N' ? "OK" : "Wrong", "\n"; __DATA__ chrX 1 3 chrX 5 6 chrX 8 9

Updated: fixed the initial value of $lastEnd. Thanks abualiga.

لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ