in reply to Re: group things?
in thread group things?
Joost's given you a solution using regexps. Here's one using split:
my $str = '-----MMMMM------IIIII----MMM---OOOO---I---MMMM-----'; my ( $start, $end ); for ( split /(-+)/, $str ) { my $char = substr $_, 0, 1; next unless length; # WTF does split return an empty string at the + start if ( $char ne '-' ) { print $start+1, length > 1 ? ( "-", $start + length ) : "", ": $char\n" } $start += length; }
Output:
6-10: M 17-21: I 26-28: M 32-35: O 39: I 43-46: M
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: group things?
by Joost (Canon) on Apr 25, 2008 at 22:46 UTC |