Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
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?
[Discipulus]: msgd daxim about his post is almost empty: in 15 minutes i'll mark for reaping
virtualsue remembers to warn Corion that Liverpool Street station is going to be a nightmare when he gets there. :-)

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2017-11-22 12:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (319 votes). Check out past polls.

    Notices?