Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: How to split_and_pad string to n-th chars pieces with one regular expression?

by Limbic~Region (Chancellor)
on Nov 30, 2007 at 14:19 UTC ( #654114=note: print w/replies, xml ) Need Help??


in reply to How to split_and_pad string to n-th chars pieces with one regular expression?

bdimych,
any advice?

Yes - stop trying to do this in a single regular expression. While I am sure there will be a dozen correct and working solutions provided, I doubt any will be self-documenting. I also suspect anyone maintaining your code will take pause when they come across it.

Why not come up with a split_by_n() function where you can pass in a string and a length and get back what you want. Heck, you could then have optional parameters for what to do with empty strings, padding or not, etc.

Cheers - L~R

  • Comment on Re: How to split_and_pad string to n-th chars pieces with one regular expression?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2023-12-11 19:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?











    Results (41 votes). Check out past polls.

    Notices?