Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Answer: How can I split a string into chunks of size n bytes?

( #74818=categorized answer: print w/ replies, xml ) Need Help??

Q&A > strings > How can I split a string into chunks of size n bytes? contributed by Masem

@bits = ( $scalar =~ /.{1,$bytes}/gs );

Edited by tye to add "s" on the end otherwise "." won't match newlines.

Edited by chipmunk to change {0,$bytes} to {1,$bytes}; otherwise a null string is matched at the end.

Comment on Answer: How can I split a string into chunks of size n bytes?
Download Code
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (15)
As of 2015-07-07 19:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls