in reply to Split Function - Positions

The below might be good enough for your purposes:
it splits up $screen into an array of single chars (using the split // idiom to split a string into each character), then loops through the resultant array to find non-X characters that are either

#! /usr/bin/perl -w use strict; my $screen = "ATCGATCGXXXXXATCGATXXXACTGCTACGGTACXXXAATTATXGCGCGXXT"; my @chars = split //, $screen; my @starts; foreach ( 0 .. scalar @chars - 1 ) { push @starts, $_ if $chars[$_] ne 'X' && ( 0 == $_ || $chars[$_-1] eq 'X' ); } print "$screen\n@starts\n";

Try checking out the bioperl modules, at http://search.cpan.org/dist/bioperl/, also. I'm not familiar with them, but they have a prepackaged routine for this.

Replies are listed 'Best First'.
Re^2: Split Function - Positions
by stajich (Chaplain) on Jun 16, 2004 at 18:13 UTC