Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found