in reply to count consecutive characters
A similar approach to moritz's but using a map instead of a while loop to take advantage of the default behaviour of length to operate on $_.
$ perl -E ' > @strs = qw{ > xxxxxxxNNNNNxxxxxNxxxxNNNNNNNNxxx > xxNxxxNNNNNNNNNxxxxxx > }; > foreach $str ( @strs ) > { > print qq{$str : }; > say join q{, }, > map length, $str =~ m{(N+)}g; > }' xxxxxxxNNNNNxxxxxNxxxxNNNNNNNNxxx : 5, 1, 8 xxNxxxNNNNNNNNNxxxxxx : 1, 9 $
I hope this is useful.
Cheers,
JohnGG
Update: Changed second print statement to a say and got rid of the say with no arguments. What was I thinking?
|
|---|