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

Re^3: Split a string into items of constant length

by truedfx (Monk)
on Oct 04, 2005 at 13:40 UTC ( [id://497246]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Split a string into items of constant length
in thread Split a string into items of constant length

Yes: of course this does not take care of the case when the given string has a length that is not a multiple of 5.
If you want to catch that, you can change the regex to /.{1,5}/g.
perl -le 'print for "ABCDEFGHIJKLMNOPQRSTUVWXYZ" =~ /.{1,5}/g' ABCDE FGHIJ KLMNO PQRST UVWXY Z
Of course, depending on what it's used for, simply discarding it can be a better idea, and /.{5}/g works just fine for that.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-19 05:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found