Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: Trouble with Transliterate Function

by choroba (Bishop)
on Aug 28, 2013 at 23:12 UTC ( #1051328=note: print w/replies, xml ) Need Help??

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.

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

Replies are listed 'Best First'.
Re^2: Trouble with Transliterate Function
by abualiga (Scribe) on Aug 29, 2013 at 03:05 UTC

    Initially I ++voted your optimization but then noticed that if the first interval range does not start with 1, the first character will not be replaced with N. I think $lastEnd=0 is the correct initial value, as in BrowserUK's solution.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1051328]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2018-04-20 10:06 GMT
Find Nodes?
    Voting Booth?