in reply to Re^4: How can I count characters between two same substrings in a string where the substring is repeated more than 5 times?
in thread How can I count characters between two same substrings in a string where the substring is repeated more than 5 times?
Actually, if the delimiter occurs at the start of the string, then split returns an empty string as the first portion. If passed a LIMIT of -1, it will also do the same at the end of the string. So if you really don't care about the lengths of the "abc" and "xyz" portions, it's simply:
use 5.010; my $string = "abcFOOdefghFOOiFOOjklmFOOnopqrFOOstuvFOOwxyz"; my @portions = split /FOO/, $string, -1; shift @portions; pop @portions; say "Lengths are:"; say $_ for map { sprintf("%d ('%s')", length, $_) } @portions;
As I said, the reason I didn't include the code to ignore the first and last portion of the string in my initial example is because it seemed obvious how it could be done.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: How can I count characters between two same substrings in a string where the substring is repeated more than 5 times?
by ww (Archbishop) on Dec 11, 2011 at 00:51 UTC |