Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: A question About Array Indexing

by AnomalousMonk (Archbishop)
on Aug 26, 2013 at 08:35 UTC ( [id://1050921]=note: print w/replies, xml ) Need Help??


in reply to A question About Array Indexing

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---'

Replies are listed 'Best First'.
Re^2: A question About Array Indexing
by ccelt09 (Sexton) on Aug 26, 2013 at 23:13 UTC

    This is a correct assumption! The only variations: 1) The test scalar will be read from an input file. 2) The inclusive ranges are also read in from a text file with the following format:

    chrX 1 60000 chrX 60038 60041 chrX 60446 60468 chrX 60689 61799 chrX 62272 62290 chrX 62703 62797

    Writing all the inclusive ranges would take a fair amount of time as there are well over 20,000. Can they also be read in within this block of code?

      BrowserUk seems to answer these questions pretty well here.

      Update: Actually, upon closer inspection, I think I would change the statement
          my( $start, $end ) = split "\t", $_;
      in the  while( <INTERVAL> ) { ... } loop to
          my( undef, $start, $end ) = split "\t", $_;
      because the interval data seems to be three-field, tab-delimited records like
      chrX    1    60000
      in which the first field, to be ignored, is a label of some kind.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (7)
As of 2024-03-28 19:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found