I don't feel I clearly understand the problem ccelt09 is trying to address, but here's an approach (one of many) that might be helpful as a first approximation to a solution. Note: No validation of ranges is done to insure against negative start/end offsets, start/end inversion, overlap, etc.

>perl -wMstrict -le "my $test = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; ;; my %inclusive_ranges = map { $_ => 1 } 7 .. 11, 18 .. 22; ;; my @excluded = grep ! $inclusive_ranges{$_}, 0 .. length($test) - 1; ;; my $str = $test; print qq{'$str'}; ;; substr $str, $_, 1, '-' for @excluded; print qq{'$str'}; " 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' '-------HIJKL------STUVW---'

Update: Another way, same caveats. Note: This approach assumes the  \x00 (null) character is never part of input data.

>perl -wMstrict -le "my $test = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; ;; my %inclusive_ranges = map { $_ => 1 } 7 .. 11, 18 .. 22; ;; my $exclude_mask = join '', map $inclusive_ranges{$_} ? qq{\xFF} : qq{\x00}, 0 .. length($test) - 1 ; ;; my $str = $test; print qq{'$str'}; ;; $str &= $exclude_mask; $str =~ tr/\x00/-/; print qq{'$str'}; " 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' '-------HIJKL------STUVW---'

In reply to Re: A question About Array Indexing by AnomalousMonk
in thread A question About Array Indexing by ccelt09

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.