Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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

by Masem (Monsignor)
on Apr 23, 2001 at 22:37 UTC ( #74818=categorized answer: print w/replies, xml ) Need Help??

Q&A > strings > How can I split a string into chunks of size n bytes? - Answer 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.

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (8)
As of 2018-02-21 12:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When it is dark outside I am happiest to see ...














    Results (279 votes). Check out past polls.

    Notices?