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
In reply to Re: Finding Start/End Position of the Uppercase Substring
by shigetsu
in thread Finding Start/End Position of the Uppercase Substring
by neversaint
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |