Jerry Preston wrote:
> Hi!
>
> I am trying to figure out a simple, Perl way to break down any sting
> similar to the following:
>
> $s0 =
>
"01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,
> 26,27,28,29";
>
> Or in any numeric order. The string cannot be longer than 55
> characters and end with ",".
>
> Ex:
>
> $s1 = "01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,";
> $s2 = "22,23,24,25,26,27,28,29"
>
> I know that I can use the following to start:
>
> if( length $s0 > 55 ) {
>
> $s1 = substr( $s0, 0, 54 );
> $s2 = substr( $s0, 54, length $s0 );
>
> }
If I understand correctly, you want to break at the longest sequence ending
with a comma, but no longer than 55 chars per segment, right? How about
something like:
while (length $s0) {
($s1, $s0) = $s0 =~ /(.{0,54}(?:,|$))(.*)/;
print "$s1\n";
}
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>