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.
In reply to Re^5: How can I count characters between two same substrings in a string where the substring is repeated more than 5 times?
by tobyink
in thread How can I count characters between two same substrings in a string where the substring is repeated more than 5 times?
by supriyoch_2008
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |