Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

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

by Lennotoecom (Pilgrim)
on Dec 06, 2013 at 18:06 UTC ( [id://1066030]=note: print w/replies, xml ) Need Help??


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

$_ = '01234567890'; push @a, $1 while s/(.{1,4})//;
update
didn't read the task properly. my bad sorry
new solution:
$_ = '01234abc'; $_ = $2.$', push @a, $& while /(.)(.{3})/;

Replies are listed 'Best First'.
Re^2: How can I split a string into chunks of 4 characters
by davido (Cardinal) on Dec 06, 2013 at 20:27 UTC

    "push @a, $1 while s/(.{1,4})//;" produces the following: "0123 4abc", which is not the desired result.


    Dave

      i will cite the author
      "For example, string "01234abc" would become array 0123 4abc"
      it is exactly what my script does
      you sir, I suppose, didn't read the task

      got mistaken. im sorry

        From the OP:

        For example, string "01234abc" would become array ("0123", "1234","234a","34ab","4abc")

        Perhaps PetreAdi made an uncited alteration to the post, but the quoted example output data is what I remember seeing when I first read it.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2026-04-13 12:06 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.