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

Re: How can I split a string into chunks of 4 characters

by kcott (Archbishop)
on Dec 07, 2013 at 14:35 UTC ( [id://1066124]=note: print w/replies, xml ) Need Help??


in reply to How can I split a string into chunks of 4 characters

G'day PetreAdi,

Here's another way to do it.

#!/usr/bin/env perl -l use strict; use warnings; my $string = '01234abc'; my @chars = split // => $string; my @chunks; push @chunks, join '' => @chars[$_ .. $_ + 3] for 0 .. length($string) + - 4; print "@chunks";

Output:

0123 1234 234a 34ab 4abc

-- Ken

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2026-04-13 02:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.