Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re^2: Split a string at a given line number

by k_manimuthu (Monk)
on May 12, 2010 at 12:29 UTC ( #839628=note: print w/replies, xml ) Need Help??

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

push @arr, $& while ($no=~ m/([^\n]+.*?\n){1,20}/gs); print "\n$_" for @arr;

Replies are listed 'Best First'.
Re^3: Split a string at a given line number
by danj35 (Sexton) on May 12, 2010 at 13:01 UTC
    That works for me, but is there a way you can split it without the newlines being removed? Thanks.

      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";
      With this, you could easily process whatever you want to process in the string.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://839628]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2016-10-21 09:42 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (288 votes). Check out past polls.