Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Split string using regex on \n or max line length

by flowdy (Scribe)
on Feb 10, 2017 at 08:08 UTC ( [id://1181638]=note: print w/replies, xml ) Need Help??


in reply to Split string using regex on \n or max line length

Hi,

I would do it in a string digestion loop:

while ( my $ltd = substr $string, 0, $LIMIT, '' ) { my @parts = split /\n/, $ltd; ... # do sth. with @parts, otherwise they will be sad }

Instead of substr, there are certainly other ways of splitting at fixed length, but this has just come to my mind first.

Update: As $string is rewritten every iteration to another place in memory, haukex' solution performs probably better. Yet I would prefer a while loop instead, swallowing everything in an array first is seldom needed.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (2)
As of 2024-04-26 02:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found