Note: Code is not tested

Here's a way to test it:

$ perl -le '$s="1234567890"x20;@s=split(/(.){70}/,$s); print length($s);print scalar @s;print join("\n",@s)' 200 5 0 0 123456789012345678901234567890123456789012345678901234567890
I'm not sure how to explain that output (5 array elements, first and third are empty strings, second and fourth are "0", fifth is 60 characters), but part of the reason might be evident from a slight change -- put the capturing close-paren after the "{70}":
$ perl -le '$s="1234567890"x20;@s=split(/(.{70})/,$s); print length($s);print scalar @s;print join("\n",@s)' 200 5 1234567890123456789012345678901234567890123456789012345678901234567890 1234567890123456789012345678901234567890123456789012345678901234567890 123456789012345678901234567890123456789012345678901234567890
That's a little better, but not quite what the OP was looking for, I think. Hard to be sure exactly what the OP was looking for, but having the first and third array elements empty (again) is probably not part of the plan.

The first element is empty because an empty string "occurs before" the first string that matches the split regex. The second array element is the part that matched the split regex (because of the parens). The third is empty, because that's what occurs before the split regex matches again. Fourth element is the second string to match the split regex. Last element is the remainder (split regex didn't match anymore).

Maybe you meant something like:

split /(?<=.{70})(.{70})/ # pos.look-behind for 70 chars, then captur +e 70
(updated to fix incorrect comment)

Let's test that:

$ perl -le '$s="1234567890"x20;@s=split(/(?<=.{70})(.{70})/,$s); print length($s);print scalar @s;print join("\n",@s)' 200 3 1234567890123456789012345678901234567890123456789012345678901234567890 1234567890123456789012345678901234567890123456789012345678901234567890 123456789012345678901234567890123456789012345678901234567890
I'm not sure if that's a "better" solution than what other monks have proposed above, but it seems to work. ;)

In reply to Re^2: spliting text!! by graff
in thread spliting text!! by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.