Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Trouble with Transliterate Function

by hdb (Monsignor)
on Aug 29, 2013 at 08:34 UTC ( [id://1051382]=note: print w/replies, xml ) Need Help??


in reply to Trouble with Transliterate Function

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1051382]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-23 20:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found