I was wondering how can I add a newline character (i.e. /n or <br>) after X number of characters.
For example, let’s say I have a perl variable $message =”aaaaabbbbbcccccdd”. I want to add a newline character after every 5 characters to this variable. So when I print the variable in html it will display:
aaaaa
bbbbb
ccccc
dd
What is the best way to do this? I was told to use substr or a count function, but I’m not sure how to go about it. Any help will be greatly appreciated. Thanks!
An even shorter option.
Outputs:
Of course I think my version is the best of all presented up to now. 😉