in reply to Finding Start/End Position of the Uppercase Substring
outputsuse strict; use warnings; my @strings = do { local $/; split /\n/, <DATA> }; foreach my $str (@strings) { my $ret = offset($str); my $substring = substr($ret->[0], $ret->[2][0], $ret->[2][1]); print <<"EOT"; $substring start character: $ret->[1][0] end character: $ret->[1][1] start offset: $ret->[2][0] end offset: $ret->[2][1] EOT } sub offset { my $str = shift; my $hyphens = 0; $hyphens++ while $str =~ /-/g; $str =~ /[A-Z]/g and my $pos_start = pos($str); $str =~ /[a-z]/g and my $pos_end = pos($str); return [ $str, [ ($pos_start - $hyphens), ($pos_end - $hyphens) - 1 ], [ $pos_start - 1, ($pos_end - $pos_start) - 1 ] ]; } __DATA__ ccaatTTTGACACACACAGAAgggca --aatTTTGACACACACAGAAgggca
Update: fix formatting.TTTGACACACACAGA start character: 6 end character: 21 start offset: 5 end offset: 15 TTTGACACACACAGA start character: 4 end character: 19 start offset: 5 end offset: 15
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Finding Start/End Position of the Uppercase Substring
by johngg (Canon) on Jun 25, 2007 at 09:49 UTC |