in reply to Re^2: Split a string at a given line number
in thread Split a string at a given line number

That works for me, but is there a way you can split it without the newlines being removed? Thanks.
  • Comment on Re^3: Split a string at a given line number

Replies are listed 'Best First'.
Re^4: Split a string at a given line number
by k_manimuthu (Monk) on May 13, 2010 at 04:28 UTC

    For my above code spliced the 20 lines and stored in a array format. Now that's changed to add a newline character in every 20th line and stored in a scalar variable.

    $new_string.="$&\n" while ($string=~ m/([^\n]+.*?\n){1,20}/gs); print "\n$new_string";
Re^4: Split a string at a given line number
by nagalenoj (Friar) on May 12, 2010 at 13:28 UTC
    With this, you could easily process whatever you want to process in the string.